LUCENE-9404: simplify checksum calculation of ByteBuffersIndexOutput

Rather than copying from buffers, we can pass the buffers directly to the checksum with good performance in JDK9+
This commit is contained in:
Robert Muir 2020-06-16 06:36:57 -04:00
parent 4decd5aa9c
commit a108f90869
No known key found for this signature in database
GPG Key ID: 817AE1DD322D7ECA
1 changed files with 2 additions and 16 deletions

View File

@ -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;
}