[clang-tools-extra] r341781 - [clangd] Make advanceTo() faster on Posting Lists

Kirill Bobyrev via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 10 00:57:28 PDT 2018


Author: omtcyfz
Date: Mon Sep 10 00:57:28 2018
New Revision: 341781

URL: http://llvm.org/viewvc/llvm-project?rev=341781&view=rev
Log:
[clangd] Make advanceTo() faster on Posting Lists

If the current element is already beyond advanceTo()'s DocID, just
return instead of doing binary search. This simple optimization saves up
to 6-7% performance,

Reviewed By: ilya-biryukov

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

Modified:
    clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp

Modified: clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp?rev=341781&r1=341780&r2=341781&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp Mon Sep 10 00:57:28 2018
@@ -38,7 +38,10 @@ public:
   /// or higher than the given one.
   void advanceTo(DocID ID) override {
     assert(!reachedEnd() && "DOCUMENT iterator can't advance() at the end.");
-    Index = std::lower_bound(Index, std::end(Documents), ID);
+    // If current ID is beyond requested one, iterator is already in the right
+    // state.
+    if (peek() < ID)
+      Index = std::lower_bound(Index, std::end(Documents), ID);
   }
 
   DocID peek() const override {




More information about the cfe-commits mailing list