avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [avro] branch master updated: AVRO-2341: Simplify ByteArrayByteSource Min Buffer Size
Date Mon, 11 Mar 2019 19:13:25 GMT
This is an automated email from the ASF dual-hosted git repository.

dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new 8c3c590  AVRO-2341: Simplify ByteArrayByteSource Min Buffer Size
8c3c590 is described below

commit 8c3c590d7bfa6d486f5741c5e2f5214a1f2436c1
Author: Beluga Behr <dam6923@gmail.com>
AuthorDate: Thu Mar 7 12:02:00 2019 -0500

    AVRO-2341: Simplify ByteArrayByteSource Min Buffer Size
---
 lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java b/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
index 93c147f..060fb62 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
@@ -21,6 +21,7 @@ import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.ByteBuffer;
+import java.util.Arrays;
 
 import org.apache.avro.AvroRuntimeException;
 import org.apache.avro.InvalidNumberEncodingException;
@@ -895,6 +896,7 @@ public class BinaryDecoder extends Decoder {
    *
    */
   private static class ByteArrayByteSource extends ByteSource {
+    private static final int MIN_SIZE = 16;
     private byte[] data;
     private int position;
     private int max;
@@ -904,9 +906,8 @@ public class BinaryDecoder extends Decoder {
       super();
       // make sure data is not too small, otherwise getLong may try and
       // read 10 bytes and get index out of bounds.
-      if (data.length < 16 || len < 16) {
-        this.data = new byte[16];
-        System.arraycopy(data, start, this.data, 0, len);
+      if (len < MIN_SIZE) {
+        this.data = Arrays.copyOfRange(data, start, start + MIN_SIZE);
         this.position = 0;
         this.max = len;
       } else {


Mime
View raw message