[PATCH] D106645: [clangd] Tweak constructor of dex AndIterator for performance.
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 23 03:42:33 PDT 2021
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; }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106645.361149.patch
Type: text/x-patch
Size: 1176 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210723/af02d5e1/attachment.bin>
More information about the cfe-commits
mailing list