ACCUMULO-2039 Make Authorizations.getAuthorizationsBB efficient Signed-off-by: Bill Havanki <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/9a34281d Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/9a34281d Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/9a34281d Branch: refs/heads/master Commit: 9a34281d394199eb0dc156d196946b76be47ac43 Parents: e99275f Author: Vikram Srivastava <[email protected]> Authored: Sat Jan 11 20:59:54 2014 -0800 Committer: Bill Havanki <[email protected]> Committed: Tue Jan 14 10:04:57 2014 -0500 ---------------------------------------------------------------------- .../apache/accumulo/core/security/Authorizations.java | 8 +++++++- .../org/apache/accumulo/core/util/ByteBufferUtil.java | 14 -------------- 2 files changed, 7 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/9a34281d/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java b/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java index 8350e2e..ab3ea68 100644 --- a/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java +++ b/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java @@ -227,7 +227,13 @@ public class Authorizations implements Iterable<byte[]>, Serializable, Authoriza * @return authorizations, each as a string encoded in UTF-8 and within a buffer */ public List<ByteBuffer> getAuthorizationsBB() { - return ByteBufferUtil.toImmutableByteBufferList(getAuthorizations()); + ArrayList<ByteBuffer> copy = new ArrayList<ByteBuffer>(authsList.size()); + for (byte[] auth : authsList) { + byte[] bytes = new byte[auth.length]; + System.arraycopy(auth, 0, bytes, 0, auth.length); + copy.add(ByteBuffer.wrap(bytes)); + } + return Collections.unmodifiableList(copy); } @Override http://git-wip-us.apache.org/repos/asf/accumulo/blob/9a34281d/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java b/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java index 6f6a9ee..b95aeda 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java +++ b/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java @@ -20,7 +20,6 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.List; import org.apache.accumulo.core.data.ByteSequence; @@ -43,19 +42,6 @@ public class ByteBufferUtil { return result; } - /** - * Provides an immutable view of a list of byte buffers, representing the same bytes. This does not protect against modifying the underlying byte arrays. - */ - public static List<ByteBuffer> toImmutableByteBufferList(Collection<byte[]> bytesList) { - if (bytesList == null) - return null; - ArrayList<ByteBuffer> result = new ArrayList<ByteBuffer>(); - for (byte[] bytes : bytesList) { - result.add(ByteBuffer.wrap(bytes)); - } - return Collections.unmodifiableList(result); - } - public static List<byte[]> toBytesList(Collection<ByteBuffer> bytesList) { if (bytesList == null) return null;
