[PATCH] D52016: [clangd] Don't create child AND and OR iterators with one posting list

Kirill Bobyrev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 13 02:40:28 PDT 2018


kbobyrev updated this revision to Diff 165229.
kbobyrev marked an inline comment as done.

https://reviews.llvm.org/D52016

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
@@ -90,7 +90,6 @@
 public:
   explicit AndIterator(std::vector<std::unique_ptr<Iterator>> AllChildren)
       : Children(std::move(AllChildren)) {
-    assert(!Children.empty() && "AND iterator should have at least one child.");
     // Establish invariants.
     sync();
     // When children are sorted by the estimateSize(), sync() calls are more
@@ -197,9 +196,7 @@
 class OrIterator : public Iterator {
 public:
   explicit OrIterator(std::vector<std::unique_ptr<Iterator>> AllChildren)
-      : Children(std::move(AllChildren)) {
-    assert(Children.size() > 0 && "OR iterator must have at least one child.");
-  }
+      : Children(std::move(AllChildren)) {}
 
   /// Returns true if all children are exhausted.
   bool reachedEnd() const override {
@@ -405,12 +402,18 @@
 
 std::unique_ptr<Iterator>
 createAnd(std::vector<std::unique_ptr<Iterator>> Children) {
-  return llvm::make_unique<AndIterator>(move(Children));
+  assert(!Children.empty() && "AND iterator should have at least one child.");
+  // If there is exactly one child, pull it one level up: AND(Child) -> Child.
+  return Children.size() == 1 ? std::move(Children.front())
+                              : llvm::make_unique<AndIterator>(move(Children));
 }
 
 std::unique_ptr<Iterator>
 createOr(std::vector<std::unique_ptr<Iterator>> Children) {
-  return llvm::make_unique<OrIterator>(move(Children));
+  assert(!Children.empty() && "OR iterator should have at least one child.");
+  // If there is exactly one child, pull it one level up: OR(Child) -> Child.
+  return Children.size() == 1 ? std::move(Children.front())
+                              : llvm::make_unique<OrIterator>(move(Children));
 }
 
 std::unique_ptr<Iterator> createTrue(DocID Size) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52016.165229.patch
Type: text/x-patch
Size: 1964 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180913/61dd52d4/attachment.bin>


More information about the cfe-commits mailing list