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
llvm-svn: 341781
/// 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 {