8281259: MutableBigInteger subtraction could be simplified
Reviewed-by: bpb
This commit is contained in:
parent
f399ae558e
commit
e73ee0ca10
@ -945,13 +945,13 @@ class MutableBigInteger {
|
||||
x--; y--;
|
||||
|
||||
diff = (a.value[x+a.offset] & LONG_MASK) -
|
||||
(b.value[y+b.offset] & LONG_MASK) - ((int)-(diff>>32));
|
||||
(b.value[y+b.offset] & LONG_MASK) + (diff >> 32);
|
||||
result[rstart--] = (int)diff;
|
||||
}
|
||||
// Subtract remainder of longer number
|
||||
while (x > 0) {
|
||||
x--;
|
||||
diff = (a.value[x+a.offset] & LONG_MASK) - ((int)-(diff>>32));
|
||||
diff = (a.value[x+a.offset] & LONG_MASK) + (diff >> 32);
|
||||
result[rstart--] = (int)diff;
|
||||
}
|
||||
|
||||
@ -986,13 +986,13 @@ class MutableBigInteger {
|
||||
while (y > 0) {
|
||||
x--; y--;
|
||||
diff = (a.value[a.offset+ x] & LONG_MASK) -
|
||||
(b.value[b.offset+ y] & LONG_MASK) - ((int)-(diff>>32));
|
||||
(b.value[b.offset+ y] & LONG_MASK) + (diff >> 32);
|
||||
a.value[a.offset+x] = (int)diff;
|
||||
}
|
||||
// Subtract remainder of longer number
|
||||
while (x > 0) {
|
||||
while (diff < 0 && x > 0) {
|
||||
x--;
|
||||
diff = (a.value[a.offset+ x] & LONG_MASK) - ((int)-(diff>>32));
|
||||
diff = (a.value[a.offset+ x] & LONG_MASK) + (diff >> 32);
|
||||
a.value[a.offset+x] = (int)diff;
|
||||
}
|
||||
|
||||
|
@ -207,4 +207,15 @@ public class BigIntegers {
|
||||
bh.consume(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
/** Invokes the gcd method of BigInteger with different values. */
|
||||
@Benchmark
|
||||
@OperationsPerInvocation(TESTSIZE)
|
||||
public void testGcd(Blackhole bh) {
|
||||
for (int i = 0; i < TESTSIZE; i++) {
|
||||
BigInteger i1 = shiftArray[TESTSIZE - i - 1];
|
||||
BigInteger i2 = shiftArray[i];
|
||||
bh.consume(i2.gcd(i1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user