Skip to content

Commit eb21dd7

Browse files
authored
Optimize a bit two more prefix sums. (#15156)
This applies the same change as #14979 to two more prefix sums. I was not able to measure speedups (or slowdowns) with luceneutil, but I think it's still better to write our prefix sums this way.
1 parent acacc8c commit eb21dd7

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lucene/core/src/java/org/apache/lucene/codecs/lucene103/Lucene103PostingsReader.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,11 @@ public void init(IndexInput termsIn, SegmentReadState state) throws IOException
204204
}
205205
}
206206

207-
static void prefixSum(int[] buffer, int count, long base) {
208-
buffer[0] += base;
209-
for (int i = 1; i < count; ++i) {
210-
buffer[i] += buffer[i - 1];
207+
static void prefixSum(int[] buffer, int count, int base) {
208+
int sum = base;
209+
for (int i = 0; i < count; ++i) {
210+
sum += buffer[i];
211+
buffer[i] = sum;
211212
}
212213
}
213214

@@ -617,9 +618,7 @@ private void refillFullBlock() throws IOException {
617618
for (int i = 0; i < numLongs - 1; ++i) {
618619
docCumulativeWordPopCounts[i] = Long.bitCount(docBitSet.getBits()[i]);
619620
}
620-
for (int i = 1; i < numLongs - 1; ++i) {
621-
docCumulativeWordPopCounts[i] += docCumulativeWordPopCounts[i - 1];
622-
}
621+
prefixSum(docCumulativeWordPopCounts, numLongs - 1, 0);
623622
docCumulativeWordPopCounts[numLongs - 1] = BLOCK_SIZE;
624623
assert docCumulativeWordPopCounts[numLongs - 2]
625624
+ Long.bitCount(docBitSet.getBits()[numLongs - 1])

0 commit comments

Comments
 (0)