summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/clangd/IndexTests.cpp
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2017-12-23 19:38:03 +0000
committerSam McCall <sam.mccall@gmail.com>2017-12-23 19:38:03 +0000
commit4b9bbb378b044f3bafa7a3281842bd5d288f529d (patch)
tree5caf0425f86d3ec45e4cc4aa1c24e5eb55ed6838 /clang-tools-extra/unittests/clangd/IndexTests.cpp
parente83ae11ccc928ae29c1987655459d17bca000f26 (diff)
downloadbcm5719-llvm-4b9bbb378b044f3bafa7a3281842bd5d288f529d.tar.gz
bcm5719-llvm-4b9bbb378b044f3bafa7a3281842bd5d288f529d.zip
[clangd] Use Builder for symbol slabs, and use sorted-vector for storage
Summary: This improves a few things: - the insert -> freeze -> read sequence is now enforced/communicated by the type system - SymbolSlab::const_iterator iterates over symbols, not over id-symbol pairs - we avoid permanently storing a second copy of the IDs, and the string map's hashtable The slab size is now down to 21.8MB for the LLVM project. Of this only 2.7MB is strings, the rest is #symbols * `sizeof(Symbol)`. `sizeof(Symbol)` is currently 96, which seems too big - I think SymbolInfo isn't efficiently packed. That's a topic for another patch! Also added simple API to see the memory usage/#symbols of a slab, since it seems likely we will continue to care about this. Reviewers: ilya-biryukov Subscribers: klimek, mgrang, cfe-commits Differential Revision: https://reviews.llvm.org/D41506 llvm-svn: 321412
Diffstat (limited to 'clang-tools-extra/unittests/clangd/IndexTests.cpp')
-rw-r--r--clang-tools-extra/unittests/clangd/IndexTests.cpp40
1 files changed, 29 insertions, 11 deletions
diff --git a/clang-tools-extra/unittests/clangd/IndexTests.cpp b/clang-tools-extra/unittests/clangd/IndexTests.cpp
index 0a4f31a7f1b..fac2895ec63 100644
--- a/clang-tools-extra/unittests/clangd/IndexTests.cpp
+++ b/clang-tools-extra/unittests/clangd/IndexTests.cpp
@@ -13,10 +13,10 @@
#include "gtest/gtest.h"
using testing::UnorderedElementsAre;
+using testing::Pointee;
namespace clang {
namespace clangd {
-
namespace {
Symbol symbol(llvm::StringRef QName) {
@@ -33,6 +33,24 @@ Symbol symbol(llvm::StringRef QName) {
return Sym;
}
+MATCHER_P(Named, N, "") { return arg.Name == N; }
+
+TEST(SymbolSlab, FindAndIterate) {
+ SymbolSlab::Builder B;
+ B.insert(symbol("Z"));
+ B.insert(symbol("Y"));
+ B.insert(symbol("X"));
+ EXPECT_EQ(nullptr, B.find(SymbolID("W")));
+ for (const char *Sym : {"X", "Y", "Z"})
+ EXPECT_THAT(B.find(SymbolID(Sym)), Pointee(Named(Sym)));
+
+ SymbolSlab S = std::move(B).build();
+ EXPECT_THAT(S, UnorderedElementsAre(Named("X"), Named("Y"), Named("Z")));
+ EXPECT_EQ(S.end(), S.find(SymbolID("W")));
+ for (const char *Sym : {"X", "Y", "Z"})
+ EXPECT_THAT(*S.find(SymbolID(Sym)), Named(Sym));
+}
+
struct SlabAndPointers {
SymbolSlab Slab;
std::vector<const Symbol *> Pointers;
@@ -45,18 +63,18 @@ struct SlabAndPointers {
std::shared_ptr<std::vector<const Symbol *>>
generateSymbols(std::vector<std::string> QualifiedNames,
std::weak_ptr<SlabAndPointers> *WeakSymbols = nullptr) {
- auto Slab = std::make_shared<SlabAndPointers>();
- if (WeakSymbols)
- *WeakSymbols = Slab;
-
+ SymbolSlab::Builder Slab;
for (llvm::StringRef QName : QualifiedNames)
- Slab->Slab.insert(symbol(QName));
-
- for (const auto &Sym : Slab->Slab)
- Slab->Pointers.push_back(&Sym.second);
+ Slab.insert(symbol(QName));
- auto *Pointers = &Slab->Pointers;
- return {std::move(Slab), Pointers};
+ auto Storage = std::make_shared<SlabAndPointers>();
+ Storage->Slab = std::move(Slab).build();
+ for (const auto &Sym : Storage->Slab)
+ Storage->Pointers.push_back(&Sym);
+ if (WeakSymbols)
+ *WeakSymbols = Storage;
+ auto *Pointers = &Storage->Pointers;
+ return {std::move(Storage), Pointers};
}
// Create a slab of symbols with IDs and names [Begin, End], otherwise identical
OpenPOWER on IntegriCloud