On Mon, 9 May 2022 20:21:21 GMT, Phil Race <p...@openjdk.org> wrote:

>>> > The current implementation creates ~750 new objects on load
>>> 
>>> Whereas yours creates an un-bounded number .. and changes that two lookups 
>>> for the same name will return the same "==" object.
>> 
>> That’s not what happens, since `XColors::lookupColor` always calls `new 
>> ColorUIResource(…)` in both the old and new version.
>> 
>> --------------------------------------------------------------------------------
>> 
>> The difference is that the old version would perform **O**(log <var>n</var>) 
>> lookups with **O**(<var>n</var>) string comparisons per lookup, whereas the 
>> new one performs a single `String.hashCode()` invocation (the result of 
>> which is cached[^1]) followed by an **O**(log <var>n</var>) `lookupswitch` 
>> and then an **O**(1) `tableswitch`.
>> 
>> [^1]: 
>> https://github.com/openjdk/jdk/blob/9583e3657e43cc1c6f2101a64534564db2a9bd84/src/java.base/share/classes/java/lang/String.java#L2335-L2355
>
>> That’s not what happens, since XColors::lookupColor always calls new 
>> ColorUIResource(…) in both the old and new version.
> 
> You are correct. I over-looked the toColor() implementation.
> 
> Ok. this should be fine once the author tag is removed.

Thank you @prrace! I will start communicating on the mailing list before making 
any changes from now on.

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

PR: https://git.openjdk.java.net/jdk/pull/7096

Reply via email to