]> git.sesse.net Git - plocate/commitdiff
Simplify docid deduplication in plocate-builder.
authorSteinar H. Gunderson <steinar+git@gunderson.no>
Sat, 3 Oct 2020 09:25:32 +0000 (11:25 +0200)
committerSteinar H. Gunderson <steinar+git@gunderson.no>
Sat, 3 Oct 2020 09:25:32 +0000 (11:25 +0200)
Doesn't matter much for speed, but feels easier to understand.

plocate-build.cpp

index c6804497248f4a9a828200d784b9450f8986ad72..bc211749af74e61993a2a0ab280cd2aed9331b81 100644 (file)
@@ -82,28 +82,25 @@ private:
 
        vector<uint32_t> pending_docids;
 
-       uint32_t last_block_end;
+       uint32_t last_block_end, last_docid = -1;
 };
 
 void PostingListBuilder::add_docid(uint32_t docid)
 {
        // Deduplicate against the last inserted value, if any.
-       if (pending_docids.empty()) {
-               if (encoded.empty()) {
-                       // Very first docid.
-                       write_header(docid);
-                       ++num_docids;
-                       last_block_end = docid;
-                       return;
-               } else if (docid == last_block_end) {
-                       return;
-               }
-       } else {
-               if (docid == pending_docids.back()) {
-                       return;
-               }
+       if (docid == last_docid) {
+               return;
+       }
+
+       if (num_docids == 0) {
+               // Very first docid.
+               write_header(docid);
+               ++num_docids;
+               last_block_end = last_docid = docid;
+               return;
        }
 
+       last_docid = docid;
        pending_docids.push_back(docid);
        if (pending_docids.size() == 128) {
                append_block();