RFR: 8287603: Avoid redundant HashMap.containsKey calls in NimbusDefaults.getDerivedColor
Andrey Turbanov
aturbanov at openjdk.java.net
Tue May 31 21:10:44 UTC 2022
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.
-------------
Commit messages:
- [PATCH] Avoid redundant HashMap.containsKey calls in NimbusDefaults
Changes: https://git.openjdk.java.net/jdk/pull/8482/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=8482&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8287603
Stats: 8 lines in 1 file changed: 1 ins; 3 del; 4 mod
Patch: https://git.openjdk.java.net/jdk/pull/8482.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/8482/head:pull/8482
PR: https://git.openjdk.java.net/jdk/pull/8482
More information about the client-libs-dev
mailing list