sammccall created this revision. sammccall added a reviewer: kbobyrev. Herald added subscribers: usaxena95, kadircet, arphaman. sammccall requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang-tools-extra.
Calling sync() *after* we sort the children is faster. Also bail out early if some child is already at end. This seems safe and should improve perf though only slightly Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D106645 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 @@ -27,10 +27,6 @@ explicit AndIterator(std::vector<std::unique_ptr<Iterator>> AllChildren) : Iterator(Kind::And), Children(std::move(AllChildren)) { assert(!Children.empty() && "AND iterator should have at least one child."); - // Establish invariants. - for (const auto &Child : Children) - ReachedEnd |= Child->reachedEnd(); - sync(); // When children are sorted by the estimateSize(), sync() calls are more // effective. Each sync() starts with the first child and makes sure all // children point to the same element. If any child is "above" the previous @@ -42,6 +38,10 @@ const std::unique_ptr<Iterator> &RHS) { return LHS->estimateSize() < RHS->estimateSize(); }); + // Establish invariants. + for (const auto &Child : Children) + ReachedEnd |= Child->reachedEnd(); + sync(); } bool reachedEnd() const override { return ReachedEnd; }
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 @@ -27,10 +27,6 @@ explicit AndIterator(std::vector<std::unique_ptr<Iterator>> AllChildren) : Iterator(Kind::And), Children(std::move(AllChildren)) { assert(!Children.empty() && "AND iterator should have at least one child."); - // Establish invariants. - for (const auto &Child : Children) - ReachedEnd |= Child->reachedEnd(); - sync(); // When children are sorted by the estimateSize(), sync() calls are more // effective. Each sync() starts with the first child and makes sure all // children point to the same element. If any child is "above" the previous @@ -42,6 +38,10 @@ const std::unique_ptr<Iterator> &RHS) { return LHS->estimateSize() < RHS->estimateSize(); }); + // Establish invariants. + for (const auto &Child : Children) + ReachedEnd |= Child->reachedEnd(); + sync(); } bool reachedEnd() const override { return ReachedEnd; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits