Author: d0k
Date: Thu Dec 28 06:47:01 2017
New Revision: 321523

URL: http://llvm.org/viewvc/llvm-project?rev=321523&view=rev
Log:
[clangd] Simplify code. No functionality change intended.

Modified:
    clang-tools-extra/trunk/clangd/index/FileIndex.cpp
    clang-tools-extra/trunk/clangd/index/FileIndex.h
    clang-tools-extra/trunk/clangd/index/Index.cpp
    clang-tools-extra/trunk/clangd/index/Index.h
    clang-tools-extra/trunk/clangd/index/MemIndex.cpp
    clang-tools-extra/trunk/clangd/index/MemIndex.h
    clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp

Modified: clang-tools-extra/trunk/clangd/index/FileIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.cpp?rev=321523&r1=321522&r2=321523&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Thu Dec 28 06:47:01 2017
@@ -37,7 +37,7 @@ void FileSymbols::update(PathRef Path, s
   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 &Ct
   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

Modified: clang-tools-extra/trunk/clangd/index/FileIndex.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.h?rev=321523&r1=321522&r2=321523&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/FileIndex.h (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.h Thu Dec 28 06:47:01 2017
@@ -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;

Modified: clang-tools-extra/trunk/clangd/index/Index.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=321523&r1=321522&r2=321523&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/Index.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Index.cpp Thu Dec 28 06:47:01 2017
@@ -29,10 +29,6 @@ void operator>>(StringRef Str, SymbolID
   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<Stri
   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;
   };

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=321523&r1=321522&r2=321523&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Thu Dec 28 06:47:01 2017
@@ -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);

Modified: clang-tools-extra/trunk/clangd/index/MemIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/MemIndex.cpp?rev=321523&r1=321522&r2=321523&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/MemIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/MemIndex.cpp Thu Dec 28 06:47:01 2017
@@ -26,8 +26,9 @@ void MemIndex::build(std::shared_ptr<std
   }
 }
 
-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 &
       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.

Modified: clang-tools-extra/trunk/clangd/index/MemIndex.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/MemIndex.h?rev=321523&r1=321522&r2=321523&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/MemIndex.h (original)
+++ clang-tools-extra/trunk/clangd/index/MemIndex.h Thu Dec 28 06:47:01 2017
@@ -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;

Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=321523&r1=321522&r2=321523&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Thu Dec 28 
06:47:01 2017
@@ -48,11 +48,10 @@ std::string makeAbsolutePath(const Sourc
       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::handleDeclOccurenc
     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;


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to