RFR: 8356891: Some code simplifications for basic BigIntegers' bit operations

Chen Liang liach at openjdk.org
Tue May 13 18:02:05 UTC 2025


On Sat, 10 May 2025 16:41:17 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.

src/java.base/share/classes/java/math/BigInteger.java line 2828:

> 2826:      * assuming there are no leading zero ints.
> 2827:      */
> 2828:     private static int bitLength(int[] val, int len) {

This should really be refactored to an instance method `bitLengthUnsigned` or `magBitCount`: the `len` is always `val.length` and the `val` is always the `mag` array of some `BigInteger` from somewhere. Making this an instance method makes code cleaner and allows us to cache if we find this calculation expensive.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25166#discussion_r2083561722


More information about the core-libs-dev mailing list