[PATCH] D50500: [clangd] Allow consuming limited number of items

Kirill Bobyrev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 9 02:43:31 PDT 2018


kbobyrev created this revision.
kbobyrev added reviewers: ioeric, ilya-biryukov.
kbobyrev added a project: clang-tools-extra.
Herald added subscribers: arphaman, jkorous, MaskRay.

This patch modifies `consume` function to allow retrieval of limited number of symbols. This is the "cheap" implementation of top-level limiting iterator. In the future we would like to have a complete limit iterator implementation to insert it into the query subtrees, but in the meantime this version would be enough for a fully-functional proof-of-concept Dex implementation.


https://reviews.llvm.org/D50500

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


Index: clang-tools-extra/clangd/index/dex/Iterator.h
===================================================================
--- clang-tools-extra/clangd/index/dex/Iterator.h
+++ clang-tools-extra/clangd/index/dex/Iterator.h
@@ -101,9 +101,12 @@
   virtual llvm::raw_ostream &dump(llvm::raw_ostream &OS) const = 0;
 };
 
-/// Exhausts given iterator and returns all processed DocIDs. The result
-/// contains sorted DocumentIDs.
-std::vector<DocID> consume(Iterator &It);
+/// Advances the iterator until it is either exhausted or the number of
+/// requested items is reached. The result contains sorted DocumentIDs. Size of
+/// the returned vector is min(Limit, IteratorSize) where IteratorSize stands
+/// for the number of elements obtained before the iterator is exhausted.
+std::vector<DocID> consume(Iterator &It,
+                           size_t Limit = std::numeric_limits<size_t>::max());
 
 /// Returns a document iterator over given PostingList.
 std::unique_ptr<Iterator> create(PostingListRef Documents);
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
@@ -218,9 +218,10 @@
 
 } // end namespace
 
-std::vector<DocID> consume(Iterator &It) {
+std::vector<DocID> consume(Iterator &It, size_t Limit) {
   std::vector<DocID> Result;
-  for (; !It.reachedEnd(); It.advance())
+  for (size_t Retreived = 0; !It.reachedEnd() && Retreived < Limit;
+       It.advance())
     Result.push_back(It.peek());
   return Result;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50500.159885.patch
Type: text/x-patch
Size: 1610 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180809/92a32e23/attachment-0001.bin>


More information about the cfe-commits mailing list