[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 03:04:37 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL342124: [clangd] Don't create child AND and OR iterators with one posting list (authored by omtcyfz, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D52016?vs=165236&id=165237#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D52016

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


Index: clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp
+++ clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp
@@ -198,7 +198,7 @@
 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.");
+    assert(!Children.empty() && "OR iterator should have at least one child.");
   }
 
   /// Returns true if all children are exhausted.
@@ -405,12 +405,16 @@
 
 std::unique_ptr<Iterator>
 createAnd(std::vector<std::unique_ptr<Iterator>> Children) {
-  return llvm::make_unique<AndIterator>(move(Children));
+  // 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));
+  // 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.165237.patch
Type: text/x-patch
Size: 1433 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180913/6334545b/attachment.bin>


More information about the cfe-commits mailing list