Hello Andrey,
On 05/09/21 12:02 am, Andrey Turbanov wrote:
src/java.base/share/classes/java/util/Properties.java line 924:
922: writeDateComment(bw);
923: synchronized (this) {
924: for (Map.Entry<Object, Object> e : new
TreeMap<>(map).entrySet()) {
Is this sorting intentionally added? It's not clear from issue description or
PR description that order of properties should be changed too.
Anyway I think copying to array and then sorting should be faster, that
creating TreeMap
Yes, the ordering of the properties is intentional as noted in the
description of this PR as well as the linked mail discussion thread.
As for the usage of TreeMap, I had looked around the JDK code to see if
there are more performant ways to order that existing Map, but I
couldn't find any. Do you mean that converting the keySet() of an
existing Map into an array and then sorting that array and then using
that sorted array to iterate and using these keys to do an additional
lookup for value against the original Map would be more efficient in
this case? I can experiment with it in a simple JMH benchmark with some
decent/regular sized Map and see how it performs.
-Jaikiran