RFR: 8356891: Some code simplifications in BigInteger [v22]
Raffaello Giulietti
rgiulietti at openjdk.org
Tue May 27 16:22:58 UTC 2025
On Wed, 21 May 2025 09:12:49 GMT, fabioromano1 <duke at openjdk.org> wrote:
>> Some changes in `Biginteger`s' bit operations that increase the code readability and slightly optimize the execution time.
>
> fabioromano1 has updated the pull request incrementally with one additional commit since the last revision:
>
> Correct typo in comment
src/java.base/share/classes/java/math/BigInteger.java line 4547:
> 4545: * If the source is trusted the copying may be skipped.
> 4546: */
> 4547: private static int[] stripLeadingZeroInts(int[] val, boolean trusted) {
I suggest to restore `trustedStripLeadingZeroInts()`, with an implementation that just invokes this one with `trusted` set to `true`.
And then restore the `trustedStripLeadingZeroInts()` invocations. The name is more intent-revealing and somewhat more conventional.
src/java.base/share/classes/java/math/BigInteger.java line 4732:
> 4730: /* Allocate output array. If all non-sign ints are 0x00, we must
> 4731: * allocate space for one extra output int. */
> 4732: for (i = a.length - 1; i >= keep && a[i] == 0; i--) // Skip trailing zeros
I think there's no need to check for `i >= keep`.
Suggestion:
for (i = a.length - 1; a[i] == 0; i--) // Skip trailing zeros
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25166#discussion_r2109478579
PR Review Comment: https://git.openjdk.org/jdk/pull/25166#discussion_r2109510018
More information about the core-libs-dev
mailing list