Skip to content

Commit c9c63d9

Browse files
committed
compute the doc range more efficiently when flushing doc block
1 parent 219cd5e commit c9c63d9

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

lucene/core/src/java/org/apache/lucene/codecs/lucene101/Lucene101PostingsWriter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,13 @@ private void flushDocBlock(boolean finishTerm) throws IOException {
429429
// storage-efficient than the next number of bits per value (which effectively slightly biases
430430
// towards the bit set approach).
431431
int bitsPerValue = forDeltaUtil.bitsRequired(docDeltaBuffer);
432-
int sum = Math.toIntExact(Arrays.stream(docDeltaBuffer).sum());
433-
int numBitSetLongs = FixedBitSet.bits2words(sum);
432+
int docRange = lastDocID - level0LastDocID;
433+
assert docRange == Arrays.stream(docDeltaBuffer).sum();
434+
int numBitSetLongs = FixedBitSet.bits2words(docRange);
434435
int numBitsNextBitsPerValue = Math.min(Integer.SIZE, bitsPerValue + 1) * BLOCK_SIZE;
435-
if (sum == BLOCK_SIZE) {
436+
if (docRange == BLOCK_SIZE) {
436437
level0Output.writeByte((byte) 0);
437-
} else if (version < VERSION_DENSE_BLOCKS_AS_BITSETS || numBitsNextBitsPerValue <= sum) {
438+
} else if (version < VERSION_DENSE_BLOCKS_AS_BITSETS || numBitsNextBitsPerValue <= docRange) {
438439
level0Output.writeByte((byte) bitsPerValue);
439440
forDeltaUtil.encodeDeltas(bitsPerValue, docDeltaBuffer, level0Output);
440441
} else {

0 commit comments

Comments
 (0)