<i18n dev> RFR: 8311188: Simplify and modernize equals and hashCode in java.text [v2]

Pavel Rappo prappo at openjdk.org
Wed Jul 5 16:42:55 UTC 2023


On Wed, 5 Jul 2023 15:46:56 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

>> Pavel Rappo has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Adhere to surrounding code style
>
> 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.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/14752#discussion_r1253369039


More information about the i18n-dev mailing list