You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by mb...@apache.org on 2015/06/15 18:26:09 UTC
[3/3] hbase git commit: HBASE-13894 Avoid visitor alloc each call of
ByteBufferArray get/putMultiple()
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/1469ac56
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/1469ac56
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/1469ac56
Branch: refs/heads/branch-1.1
Commit: 1469ac56964ccb423dfb904ef0daa17a57955ace
Parents: 31e8182
Author: Matteo Bertozzi <ma...@cloudera.com>
Authored: Mon Jun 15 09:19:50 2015 -0700
Committer: Matteo Bertozzi <ma...@cloudera.com>
Committed: Mon Jun 15 09:22:16 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/1469ac56/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 3d6d260..a8b8fa1 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);