hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mberto...@apache.org
Subject [1/3] hbase git commit: HBASE-13894 Avoid visitor alloc each call of ByteBufferArray get/putMultiple()
Date Mon, 15 Jun 2015 16:26:07 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 68b83f25c -> ceba0659f
  refs/heads/branch-1.1 31e81829b -> 1469ac569
  refs/heads/master 714668a40 -> dd086bb22


HBASE-13894 Avoid visitor alloc each call of ByteBufferArray get/putMultiple()


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/dd086bb2
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/dd086bb2
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/dd086bb2

Branch: refs/heads/master
Commit: dd086bb22f3131680f1e629d7280ecf1978efe7f
Parents: 714668a
Author: Matteo Bertozzi <matteo.bertozzi@cloudera.com>
Authored: Mon Jun 15 09:19:50 2015 -0700
Committer: Matteo Bertozzi <matteo.bertozzi@cloudera.com>
Committed: Mon Jun 15 09:19:50 2015 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/util/ByteBufferArray.java      | 33 +++++++++++---------
 1 file changed, 19 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/dd086bb2/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferArray.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferArray.java
b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferArray.java
index 2d9027b..d3414dd 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferArray.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferArray.java
@@ -44,7 +44,7 @@ public final class ByteBufferArray {
 
   /**
    * We allocate a number of byte buffers as the capacity. In order not to out
-   * of the array bounds for the last byte(see {@link ByteBufferArray#multiple}), 
+   * of the array bounds for the last byte(see {@link ByteBufferArray#multiple}),
    * we will allocate one additional buffer with capacity 0;
    * @param capacity total size of the byte buffer array
    * @param directByteBuffer true if we allocate direct buffer
@@ -96,14 +96,17 @@ public final class ByteBufferArray {
    * @return number of bytes read
    */
   public int getMultiple(long start, int len, byte[] dstArray, int dstOffset) {
-    multiple(start, len, dstArray, dstOffset, new Visitor() {
-      public void visit(ByteBuffer bb, byte[] array, int arrayIdx, int len) {
-        bb.get(array, arrayIdx, len);
-      }
-    });
+    multiple(start, len, dstArray, dstOffset, GET_MULTIPLE_VISTOR);
     return len;
   }
 
+  private final static Visitor GET_MULTIPLE_VISTOR = new Visitor() {
+    @Override
+    public void visit(ByteBuffer bb, byte[] array, int arrayIdx, int len) {
+      bb.get(array, arrayIdx, len);
+    }
+  };
+
   /**
    * Transfers bytes from the given source array into this buffer array
    * @param start start offset of this buffer array
@@ -123,13 +126,16 @@ public final class ByteBufferArray {
    *          read
    */
   public void putMultiple(long start, int len, byte[] srcArray, int srcOffset) {
-    multiple(start, len, srcArray, srcOffset, new Visitor() {
-      public void visit(ByteBuffer bb, byte[] array, int arrayIdx, int len) {
-        bb.put(array, arrayIdx, len);
-      }
-    });
+    multiple(start, len, srcArray, srcOffset, PUT_MULTIPLE_VISITOR);
   }
 
+  private final static Visitor PUT_MULTIPLE_VISITOR = new Visitor() {
+    @Override
+    public void visit(ByteBuffer bb, byte[] array, int arrayIdx, int len) {
+      bb.put(array, arrayIdx, len);
+    }
+  };
+
   private interface Visitor {
     /**
      * Visit the given byte buffer, if it is a read action, we will transfer the
@@ -178,13 +184,12 @@ public final class ByteBufferArray {
         if (i == startBuffer) {
           cnt = bufferSize - startOffset;
           if (cnt > len) cnt = len;
-          bb.limit(startOffset + cnt).position(
-              startOffset );
+          bb.limit(startOffset + cnt).position(startOffset);
         } else if (i == endBuffer) {
           cnt = endOffset;
           bb.limit(cnt).position(0);
         } else {
-          cnt = bufferSize ;
+          cnt = bufferSize;
           bb.limit(cnt).position(0);
         }
         visitor.visit(bb, array, srcIndex + arrayOffset, cnt);


Mime
View raw message