charlesconnell commented on code in PR #7418:
URL: https://github.com/apache/hbase/pull/7418#discussion_r2466877652
##########
hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferUtils.java:
##########
@@ -1055,100 +847,23 @@ public static int compareTo(ByteBuffer buf1, int o1,
int l1, byte[] buf2, int o2
return compareTo(buf2, o2, l2, buf1, o1, l1) * -1;
}
- static int compareToUnsafe(Object obj1, long o1, int l1, Object obj2, long
o2, int l2) {
- final int stride = 8;
- final int minLength = Math.min(l1, l2);
- int strideLimit = minLength & ~(stride - 1);
- int i;
-
- /*
- * Compare 8 bytes at a time. Benchmarking shows comparing 8 bytes at a
time is no slower than
- * comparing 4 bytes at a time even on 32-bit. On the other hand, it is
substantially faster on
- * 64-bit.
- */
- for (i = 0; i < strideLimit; i += stride) {
- long lw = HBasePlatformDependent.getLong(obj1, o1 + (long) i);
- long rw = HBasePlatformDependent.getLong(obj2, o2 + (long) i);
- if (lw != rw) {
- if (!UnsafeAccess.LITTLE_ENDIAN) {
- return ((lw + Long.MIN_VALUE) < (rw + Long.MIN_VALUE)) ? -1 : 1;
- }
-
- /*
- * We want to compare only the first index where left[index] !=
right[index]. This
- * corresponds to the least significant nonzero byte in lw ^ rw, since
lw and rw are
- * little-endian. Long.numberOfTrailingZeros(diff) tells us the least
significant nonzero
- * bit, and zeroing out the first three bits of L.nTZ gives us the
shift to get that least
- * significant nonzero byte. This comparison logic is based on
UnsignedBytes from guava v21
- */
- int n = Long.numberOfTrailingZeros(lw ^ rw) & ~0x7;
- return ((int) ((lw >>> n) & 0xFF)) - ((int) ((rw >>> n) & 0xFF));
- }
- }
-
- // The epilogue to cover the last (minLength % stride) elements.
- for (; i < minLength; i++) {
- int il = (HBasePlatformDependent.getByte(obj1, o1 + i) & 0xFF);
- int ir = (HBasePlatformDependent.getByte(obj2, o2 + i) & 0xFF);
- if (il != ir) {
- return il - ir;
- }
- }
- return l1 - l2;
- }
-
- static int findCommonPrefixUnsafe(Object left, long leftOffset, int
leftLength, Object right,
- long rightOffset, int rightLength) {
- final int stride = 8;
- final int minLength = Math.min(leftLength, rightLength);
- int strideLimit = minLength & ~(stride - 1);
- int result = 0;
- int i;
-
- for (i = 0; i < strideLimit; i += stride) {
- long lw = HBasePlatformDependent.getLong(left, leftOffset + (long) i);
- long rw = HBasePlatformDependent.getLong(right, rightOffset + (long) i);
-
- if (lw != rw) {
- if (!UnsafeAccess.LITTLE_ENDIAN) {
- return result + (Long.numberOfLeadingZeros(lw ^ rw) /
Bytes.SIZEOF_LONG);
- } else {
- return result + (Long.numberOfTrailingZeros(lw ^ rw) /
Bytes.SIZEOF_LONG);
- }
- } else {
- result += Bytes.SIZEOF_LONG;
- }
- }
-
- // The epilogue to cover the last (minLength % stride) elements.
- for (; i < minLength; i++) {
- byte il = HBasePlatformDependent.getByte(left, leftOffset + i);
- byte ir = HBasePlatformDependent.getByte(right, rightOffset + i);
- if (il != ir) {
- return result;
- } else {
- result++;
- }
- }
-
- return result;
- }
-
/**
* Reads a short value at the given buffer's offset.
* @param buffer input byte buffer to read
* @param offset input offset where short is
* @return short value at offset
*/
public static short toShort(ByteBuffer buffer, int offset) {
- return ConverterHolder.BEST_CONVERTER.toShort(buffer, offset);
+ return (short) BYTE_BUFFER_SHORT_VIEW_BIG_ENDIAN_VAR_HANDLE.get(buffer,
offset);
Review Comment:
Here and in the similar methods below, I'm removing some indirection by
calling the var handle directly
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]