kbobyrev created this revision. kbobyrev added a reviewer: kadircet. Herald added subscribers: cfe-commits, usaxena95, arphaman. Herald added a project: clang. kbobyrev requested review of this revision. Herald added subscribers: MaskRay, ilya-biryukov.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D89852 Files: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
Index: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h =================================================================== --- clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h +++ clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h @@ -11,6 +11,7 @@ #include "Index.pb.h" #include "index/Index.h" +#include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/StringSaver.h" @@ -71,10 +72,11 @@ /// provided by the client. /// /// The relative path passed over the wire has unix slashes. - llvm::Expected<std::string> relativePathToURI(llvm::StringRef RelativePath); + llvm::Expected<llvm::SmallString<256>> + relativePathToURI(llvm::StringRef RelativePath); /// Translates a URI from the server's backing index to a relative path /// suitable to send over the wire to the client. - llvm::Expected<std::string> uriToRelativePath(llvm::StringRef URI); + llvm::Expected<llvm::SmallString<256>> uriToRelativePath(llvm::StringRef URI); private: clangd::SymbolLocation::Position fromProtobuf(const Position &Message); @@ -95,8 +97,8 @@ /// of them can be missing (if the machines are different they don't know each /// other's specifics and will only do one-way translation), but both can not /// be missing at the same time. - llvm::Optional<std::string> RemoteIndexRoot; - llvm::Optional<std::string> LocalIndexRoot; + llvm::Optional<llvm::SmallString<256>> RemoteIndexRoot; + llvm::Optional<llvm::SmallString<256>> LocalIndexRoot; llvm::BumpPtrAllocator Arena; llvm::UniqueStringSaver Strings; }; Index: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp =================================================================== --- clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp +++ clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp @@ -54,18 +54,18 @@ llvm::sys::path::get_separator(llvm::sys::path::Style::posix); if (!RemoteIndexRoot.empty()) { assert(llvm::sys::path::is_absolute(RemoteIndexRoot)); - this->RemoteIndexRoot = llvm::sys::path::convert_to_slash( - RemoteIndexRoot, llvm::sys::path::Style::windows); - llvm::StringRef Path(*this->RemoteIndexRoot); - if (!Path.endswith(PosixSeparator)) + this->RemoteIndexRoot = + llvm::SmallString<256>(llvm::sys::path::convert_to_slash( + RemoteIndexRoot, llvm::sys::path::Style::windows)); + if (!this->RemoteIndexRoot->endswith(PosixSeparator)) *this->RemoteIndexRoot += PosixSeparator; } if (!LocalIndexRoot.empty()) { assert(llvm::sys::path::is_absolute(LocalIndexRoot)); - this->LocalIndexRoot = llvm::sys::path::convert_to_slash( - LocalIndexRoot, llvm::sys::path::Style::windows); - llvm::StringRef Path(*this->LocalIndexRoot); - if (!Path.endswith(PosixSeparator)) + this->LocalIndexRoot = + llvm::SmallString<256>(llvm::sys::path::convert_to_slash( + LocalIndexRoot, llvm::sys::path::Style::windows)); + if (!this->LocalIndexRoot->endswith(PosixSeparator)) *this->LocalIndexRoot += PosixSeparator; } assert(!RemoteIndexRoot.empty() || !LocalIndexRoot.empty()); @@ -299,7 +299,7 @@ return Result; } -llvm::Expected<std::string> +llvm::Expected<llvm::SmallString<256>> Marshaller::relativePathToURI(llvm::StringRef RelativePath) { assert(LocalIndexRoot); assert(RelativePath == llvm::sys::path::convert_to_slash(RelativePath)); @@ -310,10 +310,11 @@ llvm::SmallString<256> FullPath = llvm::StringRef(*LocalIndexRoot); llvm::sys::path::append(FullPath, RelativePath); auto Result = URI::createFile(FullPath); - return Result.toString(); + return llvm::SmallString<256>(Result.toString()); } -llvm::Expected<std::string> Marshaller::uriToRelativePath(llvm::StringRef URI) { +llvm::Expected<llvm::SmallString<256>> +Marshaller::uriToRelativePath(llvm::StringRef URI) { assert(RemoteIndexRoot); auto ParsedURI = URI::parse(URI); if (!ParsedURI) @@ -331,7 +332,7 @@ *RemoteIndexRoot); assert(Result == llvm::sys::path::convert_to_slash( Result, llvm::sys::path::Style::windows)); - return std::string(Result); + return Result; } clangd::SymbolLocation::Position @@ -375,7 +376,7 @@ auto URIString = relativePathToURI(Message.file_path()); if (!URIString) return URIString.takeError(); - Location.FileURI = Strings.save(*URIString).begin(); + Location.FileURI = Strings.save(URIString->str()).begin(); Location.Start = fromProtobuf(Message.start()); Location.End = fromProtobuf(Message.end()); return Location; @@ -387,7 +388,7 @@ auto RelativePath = uriToRelativePath(Location.FileURI); if (!RelativePath) return RelativePath.takeError(); - *Result.mutable_file_path() = *RelativePath; + *Result.mutable_file_path() = RelativePath->c_str(); *Result.mutable_start() = toProtobuf(Location.Start); *Result.mutable_end() = toProtobuf(Location.End); return Result; @@ -405,7 +406,7 @@ auto RelativePath = uriToRelativePath(Header); if (!RelativePath) return RelativePath.takeError(); - Result.set_header(*RelativePath); + Result.set_header(RelativePath->c_str()); return Result; } @@ -416,7 +417,7 @@ auto URIString = relativePathToURI(Header); if (!URIString) return URIString.takeError(); - Header = *URIString; + Header = URIString->c_str(); } return clangd::Symbol::IncludeHeaderWithReferences{Strings.save(Header), Message.references()};
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits