summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2017-12-28 14:47:01 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2017-12-28 14:47:01 +0000
commit4727c9bcae4722f6b14ff723351b63ca01220c6e (patch)
tree142c83f3287331bb59cbf86ce9eb82aed263d66a
parent4058595ccdcba895adbb791c6d7772036c41e20e (diff)
[clangd] Simplify code. No functionality change intended.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@321523 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--clangd/index/FileIndex.cpp9
-rw-r--r--clangd/index/FileIndex.h5
-rw-r--r--clangd/index/Index.cpp8
-rw-r--r--clangd/index/Index.h6
-rw-r--r--clangd/index/MemIndex.cpp14
-rw-r--r--clangd/index/MemIndex.h5
-rw-r--r--clangd/index/SymbolCollector.cpp10
7 files changed, 23 insertions, 34 deletions
diff --git a/clangd/index/FileIndex.cpp b/clangd/index/FileIndex.cpp
index ed2500ee..cc8487ac 100644
--- a/clangd/index/FileIndex.cpp
+++ b/clangd/index/FileIndex.cpp
@@ -37,7 +37,7 @@ void FileSymbols::update(PathRef Path, std::unique_ptr<SymbolSlab> Slab) {
if (!Slab)
FileToSlabs.erase(Path);
else
- FileToSlabs[Path] = std::shared_ptr<SymbolSlab>(Slab.release());
+ FileToSlabs[Path] = std::move(Slab);
}
std::shared_ptr<std::vector<const Symbol *>> FileSymbols::allSymbols() {
@@ -74,9 +74,10 @@ void FileIndex::update(const Context &Ctx, PathRef Path, ParsedAST *AST) {
Index.build(std::move(Symbols));
}
-bool FileIndex::fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
- std::function<void(const Symbol &)> Callback) const {
- return Index.fuzzyFind(Ctx, Req, std::move(Callback));
+bool FileIndex::fuzzyFind(
+ const Context &Ctx, const FuzzyFindRequest &Req,
+ llvm::function_ref<void(const Symbol &)> Callback) const {
+ return Index.fuzzyFind(Ctx, Req, Callback);
}
} // namespace clangd
diff --git a/clangd/index/FileIndex.h b/clangd/index/FileIndex.h
index 6408a25b..312373ca 100644
--- a/clangd/index/FileIndex.h
+++ b/clangd/index/FileIndex.h
@@ -60,8 +60,9 @@ public:
/// nullptr, this removes all symbols in the file
void update(const Context &Ctx, PathRef Path, ParsedAST *AST);
- bool fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
- std::function<void(const Symbol &)> Callback) const override;
+ bool
+ fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
+ llvm::function_ref<void(const Symbol &)> Callback) const override;
private:
FileSymbols FSymbols;
diff --git a/clangd/index/Index.cpp b/clangd/index/Index.cpp
index 95348582..6d26dc84 100644
--- a/clangd/index/Index.cpp
+++ b/clangd/index/Index.cpp
@@ -29,10 +29,6 @@ void operator>>(StringRef Str, SymbolID &ID) {
std::copy(HexString.begin(), HexString.end(), ID.HashValue.begin());
}
-SymbolSlab::const_iterator SymbolSlab::begin() const { return Symbols.begin(); }
-
-SymbolSlab::const_iterator SymbolSlab::end() const { return Symbols.end(); }
-
SymbolSlab::const_iterator SymbolSlab::find(const SymbolID &ID) const {
auto It = std::lower_bound(Symbols.begin(), Symbols.end(), ID,
[](const Symbol &S, const SymbolID &I) {
@@ -50,9 +46,7 @@ static void own(Symbol &S, DenseSet<StringRef> &Strings,
auto Intern = [&](StringRef &V) {
auto R = Strings.insert(V);
if (R.second) { // New entry added to the table, copy the string.
- char *Data = Arena.Allocate<char>(V.size());
- memcpy(Data, V.data(), V.size());
- *R.first = StringRef(Data, V.size());
+ *R.first = V.copy(Arena);
}
V = *R.first;
};
diff --git a/clangd/index/Index.h b/clangd/index/Index.h
index c69a6e34..5d4dff41 100644
--- a/clangd/index/Index.h
+++ b/clangd/index/Index.h
@@ -140,8 +140,8 @@ public:
SymbolSlab() = default;
- const_iterator begin() const;
- const_iterator end() const;
+ const_iterator begin() const { return Symbols.begin(); }
+ const_iterator end() const { return Symbols.end(); }
const_iterator find(const SymbolID &SymID) const;
size_t size() const { return Symbols.size(); }
@@ -214,7 +214,7 @@ public:
/// to MaxCandidateCount
virtual bool
fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
- std::function<void(const Symbol &)> Callback) const = 0;
+ llvm::function_ref<void(const Symbol &)> Callback) const = 0;
// FIXME: add interfaces for more index use cases:
// - Symbol getSymbolInfo(SymbolID);
diff --git a/clangd/index/MemIndex.cpp b/clangd/index/MemIndex.cpp
index d0d8084f..4119e231 100644
--- a/clangd/index/MemIndex.cpp
+++ b/clangd/index/MemIndex.cpp
@@ -26,8 +26,9 @@ void MemIndex::build(std::shared_ptr<std::vector<const Symbol *>> Syms) {
}
}
-bool MemIndex::fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
- std::function<void(const Symbol &)> Callback) const {
+bool MemIndex::fuzzyFind(
+ const Context &Ctx, const FuzzyFindRequest &Req,
+ llvm::function_ref<void(const Symbol &)> Callback) const {
assert(!StringRef(Req.Query).contains("::") &&
"There must be no :: in query.");
@@ -38,14 +39,7 @@ bool MemIndex::fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
const Symbol *Sym = Pair.second;
// Exact match against all possible scopes.
- bool ScopeMatched = Req.Scopes.empty();
- for (StringRef Scope : Req.Scopes) {
- if (Scope == Sym->Scope) {
- ScopeMatched = true;
- break;
- }
- }
- if (!ScopeMatched)
+ if (!Req.Scopes.empty() && !llvm::is_contained(Req.Scopes, Sym->Scope))
continue;
// FIXME(ioeric): use fuzzy matcher.
diff --git a/clangd/index/MemIndex.h b/clangd/index/MemIndex.h
index 26ae34cf..43a21700 100644
--- a/clangd/index/MemIndex.h
+++ b/clangd/index/MemIndex.h
@@ -24,8 +24,9 @@ public:
/// accessible as long as `Symbols` is kept alive.
void build(std::shared_ptr<std::vector<const Symbol *>> Symbols);
- bool fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
- std::function<void(const Symbol &)> Callback) const override;
+ bool
+ fuzzyFind(const Context &Ctx, const FuzzyFindRequest &Req,
+ llvm::function_ref<void(const Symbol &)> Callback) const override;
private:
std::shared_ptr<std::vector<const Symbol *>> Symbols;
diff --git a/clangd/index/SymbolCollector.cpp b/clangd/index/SymbolCollector.cpp
index 1442f936..3ffc1d1b 100644
--- a/clangd/index/SymbolCollector.cpp
+++ b/clangd/index/SymbolCollector.cpp
@@ -48,11 +48,10 @@ std::string makeAbsolutePath(const SourceManager &SM, StringRef Path) {
llvm::sys::path::parent_path(AbsolutePath.str()));
if (Dir) {
StringRef DirName = SM.getFileManager().getCanonicalName(Dir);
- SmallVector<char, 128> AbsoluteFilename;
+ SmallString<128> AbsoluteFilename;
llvm::sys::path::append(AbsoluteFilename, DirName,
llvm::sys::path::filename(AbsolutePath.str()));
- return llvm::StringRef(AbsoluteFilename.data(), AbsoluteFilename.size())
- .str();
+ return AbsoluteFilename.str();
}
return AbsolutePath.str();
}
@@ -85,11 +84,10 @@ bool SymbolCollector::handleDeclOccurence(
if (!ND->hasExternalFormalLinkage() || ND->isInAnonymousNamespace())
return true;
- llvm::SmallVector<char, 128> Buff;
- if (index::generateUSRForDecl(ND, Buff))
+ llvm::SmallString<128> USR;
+ if (index::generateUSRForDecl(ND, USR))
return true;
- std::string USR(Buff.data(), Buff.size());
auto ID = SymbolID(USR);
if (Symbols.find(ID) != nullptr)
return true;