RFR: 8356891: Some code simplifications for basic BigIntegers' bit operations [v6]
Raffaello Giulietti
rgiulietti at openjdk.org
Mon May 19 15:53:10 UTC 2025
On Fri, 16 May 2025 13:30:01 GMT, fabioromano1 <duke at openjdk.org> wrote:
>> src/java.base/share/classes/java/math/BigInteger.java line 3860:
>>
>>> 3858: && Integer.lowestOneBit(mag[0]) == mag[0]
>>> 3859: && numberOfTrailingZeroInts() == mag.length - 1
>>> 3860: ? magBitLength() - 1 : magBitLength();
>>
>> Suggestion:
>>
>> int[] mag = this.mag;
>> return magBitLength()
>> - (signum < 0
>> // Check if magnitude is a power of two
>> && Integer.lowestOneBit(mag[0]) == mag[0]
>> && numberOfTrailingZeroInts() == mag.length - 1
>> ? 1 : 0);
>>
>>
>> In this way, codeSize will drop from 52 to 45
>
> What is the usefulness of doing `int[] mag = this.mag;` at line 3856, since `bitLength()` does not access to `static` fields and `BigInteger` is not threadsafe, and therefore no race conditions occur?
I think the suggestion is fine.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25166#discussion_r2096038516
More information about the core-libs-dev
mailing list