in datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java [71:100]
static boolean equals(
final ResourceImpl state1, final long offsetBytes1,
final ResourceImpl state2, final long offsetBytes2, long lengthBytes) {
state1.checkValid();
ResourceImpl.checkBounds(offsetBytes1, lengthBytes, state1.getCapacity());
state2.checkValid();
ResourceImpl.checkBounds(offsetBytes2, lengthBytes, state2.getCapacity());
long cumOff1 = state1.getCumulativeOffset(offsetBytes1);
long cumOff2 = state2.getCumulativeOffset(offsetBytes2);
final Object arr1 = state1.getUnsafeObject(); //could be null
final Object arr2 = state2.getUnsafeObject(); //could be null
if ((arr1 == arr2) && (cumOff1 == cumOff2)) { return true; }
while (lengthBytes >= Long.BYTES) {
final int chunk = (int) Math.min(lengthBytes, UNSAFE_COPY_THRESHOLD_BYTES);
// int-counted loop to avoid safepoint polls (otherwise why we chunk by
// UNSAFE_COPY_MEMORY_THRESHOLD)
int i = 0;
for (; i <= (chunk - Long.BYTES); i += Long.BYTES) {
final long v1 = unsafe.getLong(arr1, cumOff1 + i);
final long v2 = unsafe.getLong(arr2, cumOff2 + i);
if (v1 != v2) { return false; }
}
lengthBytes -= i;
cumOff1 += i;
cumOff2 += i;
}
//check the remainder bytes, if any
return (lengthBytes == 0) || equalsByBytes(arr1, cumOff1, arr2, cumOff2, (int) lengthBytes);
}