RFR: 8310813: Simplify and modernize equals, hashCode, and compareTo for BigInteger [v10]

Raffaello Giulietti rgiulietti at openjdk.org
Tue Jan 9 16:05:30 UTC 2024


On Tue, 2 Jan 2024 14:37:27 GMT, Pavel Rappo <prappo at openjdk.org> wrote:

>> Please review this PR to use modern APIs and language features to simplify equals, hashCode, and compareTo for BigInteger. If you have any performance concerns, please raise them.
>> 
>> This PR is cherry-picked from a bigger, not-yet-published PR, to test the waters. That latter PR will be published soon.
>
> Pavel Rappo has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 17 additional commits since the last revision:
> 
>  - Merge branch 'master' into 8310813
>  - Merge branch 'master' into 8310813
>  - Merge branch 'master' into 8310813
>  - Merge branch 'master' into 8310813
>  - Fix bugs in Shared.createSingle
>  - Merge branch 'master' into 8310813
>  - Group params coarser (suggested by @cl4es)
>    
>    - Splits 20 params into 3 groups: (S)mall, (M)edium and (L)arge.
>      Every testXYZ method invokes M operations, where M is the maximum
>      number of elements in a group. Shorter groups are cyclically padded.
>    - Uses the org.openjdk.jmh.infra.Blackhole API and increases
>      benchmark time.
>    - Fixes a bug in Shared that precluded 0 from being in a pair.
>  - Use better overloads (suggested by @cl4es)
>    
>    - Uses simpler, more suitable overloads for the subrange
>      starting from 0
>  - Improve benchmarks
>  - Merge branch 'master' into 8310813
>  - ... and 7 more: https://git.openjdk.org/jdk/compare/adcabea9...252b7378

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

> 3996:         int i = ArraysSupport.mismatch(m1, m2, len1);
> 3997:         if (i != -1)
> 3998:             return ((m1[i] & LONG_MASK) < (m2[i] & LONG_MASK)) ? -1 : 1;

As suggested earlier, you could make us of `Integer.compareUnsigned`, which is an intrinsic not involving `long`s.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/14630#discussion_r1446287937


More information about the core-libs-dev mailing list