RFR: 8286366: (cs) Charset.put can use putIfAbsent instead of containsKey+put
Alan Bateman
alanb at openjdk.java.net
Tue May 17 06:53:49 UTC 2022
On Sat, 30 Apr 2022 08:27:10 GMT, Andrey Turbanov <aturbanov at openjdk.org> wrote:
> 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.
Marked as reviewed by alanb (Reviewer).
-------------
PR: https://git.openjdk.java.net/jdk/pull/8480
More information about the nio-dev
mailing list