diff options
Diffstat (limited to 'clang-tools-extra/clangd/FileDistance.cpp')
-rw-r--r-- | clang-tools-extra/clangd/FileDistance.cpp | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/clang-tools-extra/clangd/FileDistance.cpp b/clang-tools-extra/clangd/FileDistance.cpp index ecf8200f7f2..14581468473 100644 --- a/clang-tools-extra/clangd/FileDistance.cpp +++ b/clang-tools-extra/clangd/FileDistance.cpp @@ -36,9 +36,9 @@ #include "llvm/ADT/STLExtras.h" #include <queue> +using namespace llvm; namespace clang { namespace clangd { -using namespace llvm; // Convert a path into the canonical form. // Canonical form is either "/", or "/segment" * N: @@ -54,12 +54,12 @@ static SmallString<128> canonicalize(StringRef Path) { } constexpr const unsigned FileDistance::Unreachable; -const llvm::hash_code FileDistance::RootHash = hash_value(StringRef("/")); +const hash_code FileDistance::RootHash = hash_value(StringRef("/")); FileDistance::FileDistance(StringMap<SourceParams> Sources, const FileDistanceOptions &Opts) : Opts(Opts) { - llvm::DenseMap<hash_code, SmallVector<hash_code, 4>> DownEdges; + DenseMap<hash_code, SmallVector<hash_code, 4>> DownEdges; // Compute the best distance following only up edges. // Keep track of down edges, in case we can use them to improve on this. for (const auto &S : Sources) { @@ -68,12 +68,12 @@ FileDistance::FileDistance(StringMap<SourceParams> Sources, S.second.MaxUpTraversals); // Walk up to ancestors of this source, assigning cost. StringRef Rest = Canonical; - llvm::hash_code Hash = hash_value(Rest); + hash_code Hash = hash_value(Rest); for (unsigned I = 0; !Rest.empty(); ++I) { Rest = parent_path(Rest, sys::path::Style::posix); auto NextHash = hash_value(Rest); auto &Down = DownEdges[NextHash]; - if (!llvm::is_contained(Down, Hash)) + if (!is_contained(Down, Hash)) Down.push_back(Hash); // We can't just break after MaxUpTraversals, must still set DownEdges. if (I > S.getValue().MaxUpTraversals) { @@ -97,7 +97,7 @@ FileDistance::FileDistance(StringMap<SourceParams> Sources, // Now propagate scores parent -> child if that's an improvement. // BFS ensures we propagate down chains (must visit parents before children). std::queue<hash_code> Next; - for (auto Child : DownEdges.lookup(hash_value(llvm::StringRef("")))) + for (auto Child : DownEdges.lookup(hash_value(StringRef("")))) Next.push(Child); while (!Next.empty()) { auto Parent = Next.front(); @@ -146,8 +146,8 @@ unsigned FileDistance::distance(StringRef Path) { return Cost; } -unsigned URIDistance::distance(llvm::StringRef URI) { - auto R = Cache.try_emplace(llvm::hash_value(URI), FileDistance::Unreachable); +unsigned URIDistance::distance(StringRef URI) { + auto R = Cache.try_emplace(hash_value(URI), FileDistance::Unreachable); if (!R.second) return R.first->getSecond(); if (auto U = clangd::URI::parse(URI)) { @@ -159,10 +159,10 @@ unsigned URIDistance::distance(llvm::StringRef URI) { return R.first->second; } -FileDistance &URIDistance::forScheme(llvm::StringRef Scheme) { +FileDistance &URIDistance::forScheme(StringRef Scheme) { auto &Delegate = ByScheme[Scheme]; if (!Delegate) { - llvm::StringMap<SourceParams> SchemeSources; + StringMap<SourceParams> SchemeSources; for (const auto &Source : Sources) { if (auto U = clangd::URI::create(Source.getKey(), Scheme)) SchemeSources.try_emplace(U->body(), Source.getValue()); @@ -176,14 +176,13 @@ FileDistance &URIDistance::forScheme(llvm::StringRef Scheme) { return *Delegate; } -static std::pair<std::string, int> scopeToPath(llvm::StringRef Scope) { +static std::pair<std::string, int> scopeToPath(StringRef Scope) { SmallVector<StringRef, 4> Split; Scope.split(Split, "::", /*MaxSplit=*/-1, /*KeepEmpty=*/false); - return {"/" + llvm::join(Split, "/"), Split.size()}; + return {"/" + join(Split, "/"), Split.size()}; } -static FileDistance -createScopeFileDistance(llvm::ArrayRef<std::string> QueryScopes) { +static FileDistance createScopeFileDistance(ArrayRef<std::string> QueryScopes) { FileDistanceOptions Opts; Opts.UpCost = 2; Opts.DownCost = 4; @@ -210,10 +209,10 @@ createScopeFileDistance(llvm::ArrayRef<std::string> QueryScopes) { return FileDistance(Sources, Opts); } -ScopeDistance::ScopeDistance(llvm::ArrayRef<std::string> QueryScopes) +ScopeDistance::ScopeDistance(ArrayRef<std::string> QueryScopes) : Distance(createScopeFileDistance(QueryScopes)) {} -unsigned ScopeDistance::distance(llvm::StringRef SymbolScope) { +unsigned ScopeDistance::distance(StringRef SymbolScope) { return Distance.distance(scopeToPath(SymbolScope).first); } |