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

Pavel Rappo prappo at openjdk.org
Mon Jun 26 14:42:05 UTC 2023


On Mon, 26 Jun 2023 14:21:08 GMT, Raffaello Giulietti <rgiulietti 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.
>
> src/java.base/share/classes/java/math/BigInteger.java line 1:
> 
>> 1: /*
> 
> On L.3932, I think you can simplify
> 
>         return signum > val.signum ? 1 : -1;
> 
> with
> 
>         return signum;

Thanks for looking at this. My reply to both of your comments, is that there are further improvements possible, and I'd be happy to explore such possibilities later. Right now I'm more concerned with `hashCode` and possible performance degradation, which my local benchmarks on arm64 showed approx. 10%.

On your signum suggestion: signum of 0 is what makes that suggestion inapplicable.

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

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


More information about the core-libs-dev mailing list