You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2020/06/16 10:37:54 UTC

[lucene-solr] branch master updated: LUCENE-9404: simplify checksum calculation of ByteBuffersIndexOutput

This is an automated email from the ASF dual-hosted git repository.

rmuir pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new a108f90  LUCENE-9404: simplify checksum calculation of ByteBuffersIndexOutput
a108f90 is described below

commit a108f90869cdb030db6ba14653036a4fee58ff68
Author: Robert Muir <rm...@apache.org>
AuthorDate: Tue Jun 16 06:36:57 2020 -0400

    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+
---
 .../apache/lucene/store/ByteBuffersIndexOutput.java    | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)

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 19dc400..f6785be 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;
   }