RFR: 8287603: Avoid redundant HashMap.containsKey calls in NimbusDefaults.getDerivedColor

Alexey Ivanov aivanov at openjdk.org
Mon Jul 4 10:37:41 UTC 2022


On Sat, 30 Apr 2022 09:33:38 GMT, Andrey Turbanov <aturbanov at openjdk.org> wrote:

> The method `javax.swing.plaf.nimbus.NimbusDefaults#getDerivedColor(String,String,float,float,float,int,boolean)` could be improved by usage of Map.putIfAbsent instead of separate `containsKey`/`get`/`put` calls. We known that HashMap `javax.swing.plaf.nimbus.NimbusDefaults#derivedColors` can contain only non-null values. And to check if `putIfAbsent` was successful or not, we can just compare result with `null`.
> https://github.com/openjdk/jdk/blob/97bd4c255a319ce626a316ed211ef1fd7d0f1e14/src/java.desktop/share/classes/javax/swing/plaf/nimbus/Defaults.template#L713-L720
> It makes code a bit cleaner and faster.

Marked as reviewed by aivanov (Reviewer).

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

PR: https://git.openjdk.org/jdk/pull/8482



More information about the client-libs-dev mailing list