[clangd] Simplify code. No functionality change intended.
llvm-svn: 321523
This commit is contained in:
parent
314981bacd
commit
50a967d601
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue