fluo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mwa...@apache.org
Subject [incubator-fluo] branch master updated: inspired by #875 optimized concat of two Bytes
Date Tue, 27 Jun 2017 14:44:59 GMT
This is an automated email from the ASF dual-hosted git repository.

mwalch pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-fluo.git


The following commit(s) were added to refs/heads/master by this push:
     new 851acf0  inspired by #875 optimized concat of two Bytes
851acf0 is described below

commit 851acf0f3cddedd74f3007d5a704855b1fdad5b1
Author: Keith Turner <kturner@apache.org>
AuthorDate: Fri Jun 23 12:28:17 2017 -0400

    inspired by #875 optimized concat of two Bytes
---
 .../apache/fluo/accumulo/util/ByteArrayUtil.java    | 21 +++++++++++++++++++++
 .../org/apache/fluo/core/util/ByteUtilTest.java     | 18 ++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/modules/accumulo/src/main/java/org/apache/fluo/accumulo/util/ByteArrayUtil.java
b/modules/accumulo/src/main/java/org/apache/fluo/accumulo/util/ByteArrayUtil.java
index c1f4e5b..9906a98 100644
--- a/modules/accumulo/src/main/java/org/apache/fluo/accumulo/util/ByteArrayUtil.java
+++ b/modules/accumulo/src/main/java/org/apache/fluo/accumulo/util/ByteArrayUtil.java
@@ -91,6 +91,27 @@ public class ByteArrayUtil {
   }
 
   /**
+   * An optimized version of {@link #concat(Bytes...)} for two args that avoids creating
the varargs
+   * array.
+   *
+   */
+  public static byte[] concat(Bytes b1, Bytes b2) {
+    int offset = 0;
+    int size = b1.length() + checkVlen(b1.length()) + b2.length() + checkVlen(b2.length());
+
+    byte[] data = new byte[size];
+
+    offset = writeVint(data, offset, b1.length());
+    b1.copyTo(data, offset);
+    offset += b1.length();
+
+    offset = writeVint(data, offset, b2.length());
+    b2.copyTo(data, offset);
+
+    return data;
+  }
+
+  /**
    * Concatenates of list of Bytes objects to create a byte array
    *
    * @param listOfBytes Bytes objects to concatenate
diff --git a/modules/core/src/test/java/org/apache/fluo/core/util/ByteUtilTest.java b/modules/core/src/test/java/org/apache/fluo/core/util/ByteUtilTest.java
index 768c572..0b17961 100644
--- a/modules/core/src/test/java/org/apache/fluo/core/util/ByteUtilTest.java
+++ b/modules/core/src/test/java/org/apache/fluo/core/util/ByteUtilTest.java
@@ -63,9 +63,27 @@ public class ByteUtilTest {
 
     List<Bytes> blist = ByteArrayUtil.split(ball);
 
+    Assert.assertEquals(4, blist.size());
     Assert.assertEquals(b1, blist.get(0));
     Assert.assertEquals(b2, blist.get(1));
     Assert.assertEquals(b3, blist.get(2));
     Assert.assertEquals(b4, blist.get(3));
+
+    // test two args
+    blist = ByteArrayUtil.split(ByteArrayUtil.concat(b1, b2));
+    Assert.assertEquals(2, blist.size());
+    Assert.assertEquals(b1, blist.get(0));
+    Assert.assertEquals(b2, blist.get(1));
+
+    blist = ByteArrayUtil.split(ByteArrayUtil.concat(b4, b2));
+    Assert.assertEquals(2, blist.size());
+    Assert.assertEquals(b4, blist.get(0));
+    Assert.assertEquals(b2, blist.get(1));
+
+    blist = ByteArrayUtil.split(ByteArrayUtil.concat(b1, b4));
+    Assert.assertEquals(2, blist.size());
+    Assert.assertEquals(b1, blist.get(0));
+    Assert.assertEquals(b4, blist.get(1));
+
   }
 }

-- 
To stop receiving notification emails like this one, please contact
['"commits@fluo.apache.org" <commits@fluo.apache.org>'].

Mime
View raw message