LUCENE-10145: Revert change to computeMinMax.

This part of the change would call `ArrayUtil#getUnsignedComparator` on a
length that is rarely 4 or 8. In such cases it's better to use
`Arrays#compareUnsigned`.
This commit is contained in:
Adrien Grand 2021-10-28 16:23:00 +02:00
parent 512cad0e01
commit 53b40e0fb7
1 changed files with 15 additions and 3 deletions

View File

@ -1394,12 +1394,24 @@ public class BKDWriter implements Closeable {
BytesRef first = packedValues.apply(0);
min.copyBytes(first.bytes, first.offset + offset, length);
max.copyBytes(first.bytes, first.offset + offset, length);
final ByteArrayComparator comparator = ArrayUtil.getUnsignedComparator(length);
for (int i = 1; i < count; ++i) {
BytesRef candidate = packedValues.apply(i);
if (comparator.compare(min.bytes(), 0, candidate.bytes, candidate.offset + offset) > 0) {
if (Arrays.compareUnsigned(
min.bytes(),
0,
length,
candidate.bytes,
candidate.offset + offset,
candidate.offset + offset + length)
> 0) {
min.copyBytes(candidate.bytes, candidate.offset + offset, length);
} else if (comparator.compare(max.bytes(), 0, candidate.bytes, candidate.offset + offset)
} else if (Arrays.compareUnsigned(
max.bytes(),
0,
length,
candidate.bytes,
candidate.offset + offset,
candidate.offset + offset + length)
< 0) {
max.copyBytes(candidate.bytes, candidate.offset + offset, length);
}