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