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>(
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>(
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits