From bc935621a37e325b22b7fbf954cc12c47278ff8b Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 3 Oct 2020 11:25:32 +0200 Subject: [PATCH] Simplify docid deduplication in plocate-builder. Doesn't matter much for speed, but feels easier to understand. --- plocate-build.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/plocate-build.cpp b/plocate-build.cpp index c680449..bc21174 100644 --- a/plocate-build.cpp +++ b/plocate-build.cpp @@ -82,28 +82,25 @@ private: vector 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(); -- 2.39.2