diff --git a/ethereumj-core/src/main/java/org/ethereum/db/ByteArrayWrapper.java b/ethereumj-core/src/main/java/org/ethereum/db/ByteArrayWrapper.java index 191bd56b..f92532d3 100644 --- a/ethereumj-core/src/main/java/org/ethereum/db/ByteArrayWrapper.java +++ b/ethereumj-core/src/main/java/org/ethereum/db/ByteArrayWrapper.java @@ -1,56 +1,48 @@ package org.ethereum.db; -import com.google.common.primitives.UnsignedBytes; - import java.util.Arrays; -import java.util.Comparator; + +import org.ethereum.util.FastByteComparisons; /** * www.ethereumJ.com - * - * @author: Roman Mandeleil - * Created on: 11/06/2014 15:02 + * + * @author: Roman Mandeleil Created on: 11/06/2014 15:02 */ +public class ByteArrayWrapper implements Comparable { -public class ByteArrayWrapper implements Comparable{ + private final byte[] data; - private final byte[] data; + public ByteArrayWrapper(byte[] data) { + if (data == null) { + throw new NullPointerException(); + } + this.data = data; + } - public ByteArrayWrapper(byte[] data) - { - if (data == null) - { - throw new NullPointerException(); - } - this.data = data; - } + public boolean equals(Object other) { + if (!(other instanceof ByteArrayWrapper)) { + return false; + } + byte[] otherData = ((ByteArrayWrapper) other).getData(); + return FastByteComparisons.compareTo( + data, 0, data.length, + otherData, 0, otherData.length) == 0; + } - @Override - public boolean equals(Object other) - { - if (!(other instanceof ByteArrayWrapper)) - { - return false; - } - return Arrays.equals(data, ((ByteArrayWrapper)other).data); - } + @Override + public int hashCode() { + return Arrays.hashCode(data); + } - @Override - public int hashCode() - { - return Arrays.hashCode(data); - } - - - public byte[] getData() { - return data; - } - - @Override - public int compareTo(Object second) { - - Comparator comparator = UnsignedBytes.lexicographicalComparator(); - - return comparator.compare(this.data, ((ByteArrayWrapper)second).getData()); - } + @Override + public int compareTo(ByteArrayWrapper o) { + return FastByteComparisons.compareTo( + data, 0, data.length, + o.getData(), 0, o.getData().length); + } + + public byte[] getData() { + return data; + } }