RFR: 8286366: (cs) Charset.put can use putIfAbsent instead of containsKey+put
Andrey Turbanov
aturbanov at openjdk.java.net
Sun May 15 08:39:13 UTC 2022
The method `Charset.put(Iterator<Charset> i, Map<String,Charset> m)` could be improved by usage of `Map.putIfAbsent` instead of pair `containsKey`+`put`. This method is called only with `TreeMap` as an argument and `TreeMap` has an effective implementation of `putIfAbsent` which avoid traversal Tree twice.
According to [JDK-8176894](https://bugs.openjdk.java.net/browse/JDK-8176894) usage of `TreeMap.putIfAbsent` could improve performance by 40%-100% compared with previous approach.
-------------
Commit messages:
- [PATCH] Avoid redundant TreeMap.containsKey call in Charset.put
Changes: https://git.openjdk.java.net/jdk/pull/8480/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=8480&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8286366
Stats: 3 lines in 1 file changed: 0 ins; 1 del; 2 mod
Patch: https://git.openjdk.java.net/jdk/pull/8480.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/8480/head:pull/8480
PR: https://git.openjdk.java.net/jdk/pull/8480
More information about the nio-dev
mailing list