Skip to content

Commit dce8f71

Browse files
committed
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 66353c5 commit dce8f71

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
@@ -211,10 +211,11 @@ public void init(IndexInput termsIn, SegmentReadState state) throws IOException
211211
}
212212
}
213213

214-
static void prefixSum(int[] buffer, int count, long base) {
215-
buffer[0] += base;
216-
for (int i = 1; i < count; ++i) {
217-
buffer[i] += buffer[i - 1];
214+
static void prefixSum(int[] buffer, int count, int base) {
215+
int sum = base;
216+
for (int i = 0; i < count; ++i) {
217+
sum += buffer[i];
218+
buffer[i] = sum;
218219
}
219220
}
220221

@@ -624,9 +625,7 @@ private void refillFullBlock() throws IOException {
624625
for (int i = 0; i < numLongs - 1; ++i) {
625626
docCumulativeWordPopCounts[i] = Long.bitCount(docBitSet.getBits()[i]);
626627
}
627-
for (int i = 1; i < numLongs - 1; ++i) {
628-
docCumulativeWordPopCounts[i] += docCumulativeWordPopCounts[i - 1];
629-
}
628+
prefixSum(docCumulativeWordPopCounts, numLongs - 1, 0);
630629
docCumulativeWordPopCounts[numLongs - 1] = BLOCK_SIZE;
631630
assert docCumulativeWordPopCounts[numLongs - 2]
632631
+ Long.bitCount(docBitSet.getBits()[numLongs - 1])

0 commit comments

Comments
 (0)