[clang-tools-extra] r344745 - [clangd] Clear the semantic of RefSlab::size.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 18 08:33:20 PDT 2018


Author: hokein
Date: Thu Oct 18 08:33:20 2018
New Revision: 344745

URL: http://llvm.org/viewvc/llvm-project?rev=344745&view=rev
Log:
[clangd] Clear the semantic of RefSlab::size.

Summary:
The RefSlab::size can easily cause confusions, it returns the number of
different symbols, rahter than the number of all references.

- add numRefs() method and cache it, since calculating it everytime is nontrivial.
- clear misused places.

Reviewers: sammccall

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D53389

Modified:
    clang-tools-extra/trunk/clangd/index/Background.cpp
    clang-tools-extra/trunk/clangd/index/FileIndex.cpp
    clang-tools-extra/trunk/clangd/index/Index.cpp
    clang-tools-extra/trunk/clangd/index/Index.h
    clang-tools-extra/trunk/clangd/index/Serialization.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=344745&r1=344744&r2=344745&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Oct 18 08:33:20 2018
@@ -174,9 +174,9 @@ llvm::Error BackgroundIndex::index(tooli
   Action->EndSourceFile();
 
   log("Indexed {0} ({1} symbols, {2} refs)", Inputs.CompileCommand.Filename,
-      Symbols.size(), Refs.size());
+      Symbols.size(), Refs.numRefs());
   SPAN_ATTACH(Tracer, "symbols", int(Symbols.size()));
-  SPAN_ATTACH(Tracer, "refs", int(Refs.size()));
+  SPAN_ATTACH(Tracer, "refs", int(Refs.numRefs()));
   // FIXME: partition the symbols by file rather than TU, to avoid duplication.
   IndexedSymbols.update(AbsolutePath,
                         llvm::make_unique<SymbolSlab>(std::move(Symbols)),

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=344745&r1=344744&r2=344745&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Thu Oct 18 08:33:20 2018
@@ -63,9 +63,9 @@ indexSymbols(ASTContext &AST, std::share
   auto Refs = Collector.takeRefs();
   vlog("index AST for {0} (main={1}): \n"
        "  symbol slab: {2} symbols, {3} bytes\n"
-       "  ref slab: {4} symbols, {5} bytes",
+       "  ref slab: {4} symbols, {5} refs, {6} bytes",
        FileName, IsIndexMainAST, Syms.size(), Syms.bytes(), Refs.size(),
-       Refs.bytes());
+       Refs.numRefs(), Refs.bytes());
   return {std::move(Syms), std::move(Refs)};
 }
 

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=344745&r1=344744&r2=344745&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/Index.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Index.cpp Thu Oct 18 08:33:20 2018
@@ -172,17 +172,19 @@ RefSlab RefSlab::Builder::build() && {
   // Reallocate refs on the arena to reduce waste and indirections when reading.
   std::vector<std::pair<SymbolID, ArrayRef<Ref>>> Result;
   Result.reserve(Refs.size());
+  size_t NumRefs = 0;
   for (auto &Sym : Refs) {
     auto &SymRefs = Sym.second;
     llvm::sort(SymRefs);
     // FIXME: do we really need to dedup?
     SymRefs.erase(std::unique(SymRefs.begin(), SymRefs.end()), SymRefs.end());
 
+    NumRefs += SymRefs.size();
     auto *Array = Arena.Allocate<Ref>(SymRefs.size());
     std::uninitialized_copy(SymRefs.begin(), SymRefs.end(), Array);
     Result.emplace_back(Sym.first, ArrayRef<Ref>(Array, SymRefs.size()));
   }
-  return RefSlab(std::move(Result), std::move(Arena));
+  return RefSlab(std::move(Result), std::move(Arena), NumRefs);
 }
 
 void SwapIndex::reset(std::unique_ptr<SymbolIndex> Index) {

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=344745&r1=344744&r2=344745&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Thu Oct 18 08:33:20 2018
@@ -407,7 +407,9 @@ public:
 
   const_iterator begin() const { return Refs.begin(); }
   const_iterator end() const { return Refs.end(); }
+  /// Gets the number of symbols.
   size_t size() const { return Refs.size(); }
+  size_t numRefs() const { return NumRefs; }
   bool empty() const { return Refs.empty(); }
 
   size_t bytes() const {
@@ -431,11 +433,14 @@ public:
   };
 
 private:
-  RefSlab(std::vector<value_type> Refs, llvm::BumpPtrAllocator Arena)
-      : Arena(std::move(Arena)), Refs(std::move(Refs)) {}
+  RefSlab(std::vector<value_type> Refs, llvm::BumpPtrAllocator Arena,
+          size_t NumRefs)
+      : Arena(std::move(Arena)), Refs(std::move(Refs)), NumRefs(NumRefs) {}
 
   llvm::BumpPtrAllocator Arena;
   std::vector<value_type> Refs;
+  // Number of all references.
+  size_t NumRefs = 0;
 };
 
 struct FuzzyFindRequest {

Modified: clang-tools-extra/trunk/clangd/index/Serialization.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Serialization.cpp?rev=344745&r1=344744&r2=344745&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/Serialization.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Serialization.cpp Thu Oct 18 08:33:20 2018
@@ -496,18 +496,18 @@ std::unique_ptr<SymbolIndex> loadIndex(l
     }
   }
 
-  size_t SymSize = Symbols.size();
-  size_t RefSize = Refs.size();
+  size_t NumSym = Symbols.size();
+  size_t NumRefs = Refs.numRefs();
+
   trace::Span Tracer("BuildIndex");
   auto Index =
       UseDex ? dex::Dex::build(std::move(Symbols), std::move(Refs), URISchemes)
              : MemIndex::build(std::move(Symbols), std::move(Refs));
   vlog("Loaded {0} from {1} with estimated memory usage {2} bytes\n"
-       "  - number of symbos: {3}\n"
+       "  - number of symbols: {3}\n"
        "  - number of refs: {4}\n",
        UseDex ? "Dex" : "MemIndex", SymbolFilename,
-       Index->estimateMemoryUsage(),
-       SymSize, RefSize);
+       Index->estimateMemoryUsage(), NumSym, NumRefs);
   return Index;
 }
 




More information about the cfe-commits mailing list