Skip to content

Apache Lucene open-source search software

LUCENE-9404: simplify checksum calculation of ByteBuffersIndexOutput

Robert Muira108f90869cd
diff --git a/lucene/core/src/java/org/apache/lucene/store/ByteBuffersIndexOutput.java b/lucene/core/src/java/org/apache/lucene/store/ByteBuffersIndexOutput.java
index 19dc4004853..f6785bef79d 100644
--- a/lucene/core/src/java/org/apache/lucene/store/ByteBuffersIndexOutput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/ByteBuffersIndexOutput.java
@@ -81,24 +81,10 @@ public final class ByteBuffersIndexOutput extends IndexOutput {
if (lastChecksumPosition != delegate.size()) {
lastChecksumPosition = delegate.size();
checksum.reset();
- byte [] buffer = null;
for (ByteBuffer bb : delegate.toBufferList()) {
- if (bb.hasArray()) {
- checksum.update(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining());
- } else {
- if (buffer == null) buffer = new byte [1024 * 4];
-
- bb = bb.asReadOnlyBuffer();
- int remaining = bb.remaining();
- while (remaining > 0) {
- int len = Math.min(remaining, buffer.length);
- bb.get(buffer, 0, len);
- checksum.update(buffer, 0, len);
- remaining -= len;
- }
- }
+ checksum.update(bb);
}
- lastChecksum = checksum.getValue();
+ lastChecksum = checksum.getValue();
}
return lastChecksum;
}