<i18n dev> RFR: 8311188: Simplify and modernize equals and hashCode in java.text [v3]
Roger Riggs
rriggs at openjdk.org
Wed Jul 5 17:48:01 UTC 2023
On Wed, 5 Jul 2023 16:39:58 GMT, Pavel Rappo <prappo at openjdk.org> wrote:
>> src/java.base/share/classes/java/text/CompactNumberFormat.java line 2364:
>>
>>> 2362: return true;
>>> 2363: }
>>> 2364:
>>
>> Moving this before the `super.equals` call performance-wise would favor the equals case. (statistics not available guess)
>>
>> The code style in these files favors `if (this == obj)`... over the swapped order of arguments.
>
> You are right, I have no stats. Performance-wise, it's already better than what was there before. Before, there was no short-circuit check. But I can go either way; I don't have a strong opinion.
>
> Reusing superclass' equals is not often seen these days (and that code is old), so some amount of overlap is expected. Regardless of whether we rearrange that check or not, if the passed object is not `this`, we end up checking `this == obj` twice: once in super.equals, the other time in here.
True, there's no simple way to avoid the double check in either the equal or not equal case.
And I don't know enough about the Hotspot compiler to know whether it would spot the duplication and optimize it.
In many `equals` methods, the test for self equality is frequently the first line.
Is fine as is.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/14752#discussion_r1253438509
More information about the i18n-dev
mailing list