On Sun, 8 May 2022 02:44:24 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

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

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

Reply via email to