Skip to content

Commit

Permalink
only flush the buffer if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
jfboeuf committed Nov 13, 2024
1 parent dd096a8 commit 3f21cd0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lucene/core/src/java/org/apache/lucene/store/BufferedChecksum.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,21 @@ void updateLong(long val) {
}

void updateLongs(long[] vals, int offset, int len) {
flush();
if (upto > 0) {
int remainingCapacityInLong = Math.min((buffer.length - upto) / Long.BYTES, len);
for (int i = 0; i < remainingCapacityInLong; i++, offset++, len--) {
updateLong(vals[offset]);
}
if (0 == len) return;
}

LongBuffer b = ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
final int bufferSizeInLongs = buffer.length / Long.BYTES;
final int capacityInLong = buffer.length / Long.BYTES;
while (len > 0) {
int l = Math.min(bufferSizeInLongs, len);
flush();
int l = Math.min(capacityInLong, len);
b.put(0, vals, offset, l);
in.update(buffer, 0, l * Long.BYTES);
upto += l * Long.BYTES;
offset += l;
len -= l;
}
Expand Down

0 comments on commit 3f21cd0

Please sign in to comment.