[PATCH] D56592: [clangd] Do not override contents of the shards without modification
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 11 04:44:04 PST 2019
kadircet created this revision.
kadircet added a reviewer: ilya-biryukov.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay, ioeric.
We were writing shards with empty symbol and ref slabs whenever there
were no change in the file. Just skip the shards that has up-to-date content.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D56592
Files:
clangd/index/Background.cpp
unittests/clangd/BackgroundIndexTests.cpp
Index: unittests/clangd/BackgroundIndexTests.cpp
===================================================================
--- unittests/clangd/BackgroundIndexTests.cpp
+++ unittests/clangd/BackgroundIndexTests.cpp
@@ -351,8 +351,11 @@
EXPECT_EQ(CacheHits, 2U); // Check both A.cc and A.h loaded from cache.
// Check if the new symbol has arrived.
- auto ShardSource = MSS.loadShard(testPath("root/A.cc"));
+ ShardHeader = MSS.loadShard(testPath("root/A.h"));
EXPECT_NE(ShardHeader, nullptr);
+ EXPECT_THAT(*ShardHeader->Symbols, Contains(Named("A_CCnew")));
+ auto ShardSource = MSS.loadShard(testPath("root/A.cc"));
+ EXPECT_NE(ShardSource, nullptr);
EXPECT_THAT(*ShardSource->Symbols,
Contains(AllOf(Named("f_b"), Declared(), Defined())));
}
Index: clangd/index/Background.cpp
===================================================================
--- clangd/index/Background.cpp
+++ clangd/index/Background.cpp
@@ -306,17 +306,20 @@
// Build and store new slabs for each updated file.
for (const auto &I : *Index.Sources) {
+ // We already have the map from uris to absolutepaths in the cache,
+ // therefore traverse Index.Sources rather than Files to get rid of absolute
+ // path to uri conversion.
std::string Path = URICache.resolve(I.first());
+ auto FileIt = Files.find(Path);
+ if (FileIt == Files.end())
+ continue;
SymbolSlab::Builder Syms;
RefSlab::Builder Refs;
- auto FileIt = Files.find(Path);
- if (FileIt != Files.end()) {
- auto &F = *FileIt;
- for (const auto *S : F.second.Symbols)
- Syms.insert(*S);
- for (const auto *R : F.second.Refs)
- Refs.insert(RefToIDs[R], *R);
- }
+ auto &F = *FileIt;
+ for (const auto *S : F.second.Symbols)
+ Syms.insert(*S);
+ for (const auto *R : F.second.Refs)
+ Refs.insert(RefToIDs[R], *R);
auto SS = llvm::make_unique<SymbolSlab>(std::move(Syms).build());
auto RS = llvm::make_unique<RefSlab>(std::move(Refs).build());
auto IG = llvm::make_unique<IncludeGraph>(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56592.181248.patch
Type: text/x-patch
Size: 2062 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190111/1668cf0f/attachment.bin>
More information about the cfe-commits
mailing list