kaivalnp commented on code in PR #15303:
URL: https://github.com/apache/lucene/pull/15303#discussion_r2427154740
##########
lucene/core/src/java/org/apache/lucene/util/NumericUtils.java:
##########
@@ -94,17 +94,35 @@ public static int sortableFloatBits(int bits) {
public static void subtract(int bytesPerDim, int dim, byte[] a, byte[] b,
byte[] result) {
int start = dim * bytesPerDim;
int end = start + bytesPerDim;
+
int borrow = 0;
- for (int i = end - 1; i >= start; i--) {
- int diff = (a[i] & 0xff) - (b[i] & 0xff) - borrow;
+ int i;
+
+ int limit = start + (bytesPerDim & ~3);
+ for (i = end - 1; i >= limit; i--) {
+ int diff = Byte.toUnsignedInt(a[i]) - Byte.toUnsignedInt(b[i]) - borrow;
if (diff < 0) {
- diff += 256;
borrow = 1;
} else {
borrow = 0;
}
result[i - start] = (byte) diff;
}
+
+ for (i -= 3; i >= start; i -= 4) {
+ int aInt = (int) BitUtil.VH_BE_INT.get(a, i);
+ int bInt = (int) BitUtil.VH_BE_INT.get(b, i);
+
+ long diff = Integer.toUnsignedLong(aInt) - Integer.toUnsignedLong(bInt)
- borrow;
+ if (diff < 0) {
+ borrow = 1;
+ } else {
+ borrow = 0;
+ }
+
+ BitUtil.VH_BE_INT.set(result, i - start, (int) diff);
Review Comment:
[`BitUtil.VH_BE_INT`](https://github.com/apache/lucene/blob/e3184cbe47a7bf429bd2be06d48f56687fcc05c6/lucene/core/src/java/org/apache/lucene/util/BitUtil.java#L155-L163)
will need to be un-deprecated if we go ahead with this?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]