kbobyrev updated this revision to Diff 299934.
kbobyrev marked 3 inline comments as done.
kbobyrev added a comment.
Get rid of llvm::Optional in local and remote paths.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D89852/new/
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
@@ -95,8 +95,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;
+ std::string RemoteIndexRoot;
+ std::string 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
@@ -56,17 +56,17 @@
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);
+ llvm::StringRef Path(this->RemoteIndexRoot);
if (!Path.endswith(PosixSeparator))
- *this->RemoteIndexRoot += 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);
+ llvm::StringRef Path(this->LocalIndexRoot);
if (!Path.endswith(PosixSeparator))
- *this->LocalIndexRoot += PosixSeparator;
+ this->LocalIndexRoot += PosixSeparator;
}
assert(!RemoteIndexRoot.empty() || !LocalIndexRoot.empty());
}
@@ -83,7 +83,7 @@
llvm::Expected<clangd::FuzzyFindRequest>
Marshaller::fromProtobuf(const FuzzyFindRequest *Message) {
- assert(RemoteIndexRoot);
+ assert(!RemoteIndexRoot.empty());
clangd::FuzzyFindRequest Result;
Result.Query = Message->query();
for (const auto &Scope : Message->scopes())
@@ -93,7 +93,7 @@
Result.Limit = Message->limit();
Result.RestrictForCodeCompletion = Message->restricted_for_code_completion();
for (const auto &Path : Message->proximity_paths()) {
- llvm::SmallString<256> LocalPath = llvm::StringRef(*RemoteIndexRoot);
+ llvm::SmallString<256> LocalPath = llvm::StringRef(RemoteIndexRoot);
llvm::sys::path::append(LocalPath, Path);
// FuzzyFindRequest requires proximity paths to have platform-native format
// in order for SymbolIndex to process the query correctly.
@@ -202,7 +202,7 @@
}
FuzzyFindRequest Marshaller::toProtobuf(const clangd::FuzzyFindRequest &From) {
- assert(LocalIndexRoot);
+ assert(!LocalIndexRoot.empty());
FuzzyFindRequest RPCRequest;
RPCRequest.set_query(From.Query);
for (const auto &Scope : From.Scopes)
@@ -213,7 +213,7 @@
RPCRequest.set_restricted_for_code_completion(From.RestrictForCodeCompletion);
for (const auto &Path : From.ProximityPaths) {
llvm::SmallString<256> RelativePath = llvm::StringRef(Path);
- if (llvm::sys::path::replace_path_prefix(RelativePath, *LocalIndexRoot, ""))
+ if (llvm::sys::path::replace_path_prefix(RelativePath, LocalIndexRoot, ""))
RPCRequest.add_proximity_paths(llvm::sys::path::convert_to_slash(
RelativePath, llvm::sys::path::Style::windows));
}
@@ -301,20 +301,20 @@
llvm::Expected<std::string>
Marshaller::relativePathToURI(llvm::StringRef RelativePath) {
- assert(LocalIndexRoot);
+ assert(!LocalIndexRoot.empty());
assert(RelativePath == llvm::sys::path::convert_to_slash(RelativePath));
if (RelativePath.empty())
return error("Empty relative path.");
if (llvm::sys::path::is_absolute(RelativePath, llvm::sys::path::Style::posix))
return error("RelativePath '{0}' is absolute.", RelativePath);
- llvm::SmallString<256> FullPath = llvm::StringRef(*LocalIndexRoot);
+ llvm::SmallString<256> FullPath = llvm::StringRef(LocalIndexRoot);
llvm::sys::path::append(FullPath, RelativePath);
auto Result = URI::createFile(FullPath);
return Result.toString();
}
llvm::Expected<std::string> Marshaller::uriToRelativePath(llvm::StringRef URI) {
- assert(RemoteIndexRoot);
+ assert(!RemoteIndexRoot.empty());
auto ParsedURI = URI::parse(URI);
if (!ParsedURI)
return ParsedURI.takeError();
@@ -326,9 +326,9 @@
if (llvm::sys::path::is_absolute(Path.substr(1),
llvm::sys::path::Style::windows))
Result = Path.drop_front();
- if (!llvm::sys::path::replace_path_prefix(Result, *RemoteIndexRoot, ""))
+ if (!llvm::sys::path::replace_path_prefix(Result, RemoteIndexRoot, ""))
return error("File path '{0}' doesn't start with '{1}'.", Result.str(),
- *RemoteIndexRoot);
+ RemoteIndexRoot);
assert(Result == llvm::sys::path::convert_to_slash(
Result, llvm::sys::path::Style::windows));
return std::string(Result);
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits