fixes #826
-Updated hashCode() to direct access array
-Updated compareTo() to direct access array
-Remove calls to length() where direct access was acceptable
diff --git a/modules/api/src/main/java/org/apache/fluo/api/data/Bytes.java b/modules/api/src/main/java/org/apache/fluo/api/data/Bytes.java
index e5bde63..1e66a22 100644
--- a/modules/api/src/main/java/org/apache/fluo/api/data/Bytes.java
+++ b/modules/api/src/main/java/org/apache/fluo/api/data/Bytes.java
@@ -202,17 +202,16 @@
} else if (this.length == this.data.length && other.length == other.data.length) {
return UnsignedBytes.lexicographicalComparator().compare(this.data, other.data);
} else {
- int minLen = Math.min(this.length(), other.length());
-
- for (int i = 0; i < minLen; i++) {
- int a = (this.byteAt(i) & 0xff);
- int b = (other.byteAt(i) & 0xff);
+ int minLen = Math.min(this.length, other.length);
+ for (int i = this.offset, j = other.offset; i < minLen; i++, j++) {
+ int a = (this.data[i] & 0xff);
+ int b = (other.data[j] & 0xff);
if (a != b) {
return a - b;
}
}
- return this.length() - other.length();
+ return this.length - other.length;
}
}
@@ -229,7 +228,7 @@
if (other instanceof Bytes) {
Bytes ob = (Bytes) other;
- if (length() != ob.length()) {
+ if (length != ob.length) {
return false;
}
@@ -242,8 +241,9 @@
public final int hashCode() {
if (hashCode == 0) {
int hash = 1;
- for (int i = 0; i < length(); i++) {
- hash = (31 * hash) + byteAt(i);
+ int end = offset + length;
+ for (int i = offset; i < end; i++) {
+ hash = (31 * hash) + data[i];
}
hashCode = hash;
}
@@ -457,7 +457,7 @@
}
public BytesBuilder append(Bytes b) {
- ensureCapacity(len + b.length());
+ ensureCapacity(len + b.length);
System.arraycopy(b.data, b.offset, ba, len, b.length);
len += b.length();
return this;