in cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/bulkwriter/util/FastByteOperations.java [213:246]
static int compareTo(Object buffer1, long offset1, int length1, Object buffer2, long offset2, int length2)
{
int minLength = Math.min(length1, length2);
/*
* 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.
*/
int wordComparisons = minLength & ~7;
for (int index = 0; index < wordComparisons; index += Longs.BYTES)
{
long long1 = UNSAFE.getLong(buffer1, offset1 + index);
long long2 = UNSAFE.getLong(buffer2, offset2 + index);
if (long1 != long2)
{
return BIG_ENDIAN ? UnsignedLongs.compare(long1, long2)
: UnsignedLongs.compare(Long.reverseBytes(long1), Long.reverseBytes(long2));
}
}
for (int index = wordComparisons; index < minLength; index++)
{
int byte1 = UNSAFE.getByte(buffer1, offset1 + index) & 0xFF;
int byte2 = UNSAFE.getByte(buffer2, offset2 + index) & 0xFF;
if (byte1 != byte2)
{
return byte1 - byte2;
}
}
return length1 - length2;
}