kbobyrev updated this revision to Diff 164623.
kbobyrev marked an inline comment as done.
kbobyrev added a comment.

Add a short comment on why calling `lower_bound` is redundant. Also, don't 
spend extra line on return by inverting the condition.


https://reviews.llvm.org/D51802

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


Index: clang-tools-extra/clangd/index/dex/Iterator.cpp
===================================================================
--- clang-tools-extra/clangd/index/dex/Iterator.cpp
+++ clang-tools-extra/clangd/index/dex/Iterator.cpp
@@ -38,7 +38,10 @@
   /// 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 {


Index: clang-tools-extra/clangd/index/dex/Iterator.cpp
===================================================================
--- clang-tools-extra/clangd/index/dex/Iterator.cpp
+++ clang-tools-extra/clangd/index/dex/Iterator.cpp
@@ -38,7 +38,10 @@
   /// 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

Reply via email to