-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
11
A DESCRIPTION OF THE PROBLEM :
Map.copyOf first creates a temporary array of entries before calling Map.ofEntries.
Then Map.ofEntries creates another temporary array of objects before calling ImmutableCollections.MapN.
Finally ImmutableCollections.MapN constructor creates the final object array (table field).
By simply having another constructor for ImmutableCollections.MapN taking a Set<Map.Entry> as parameter, the two temporary arrays creation/copy could be avoided. Map.copyOf could directly call ImmutableCollections.MapN with map.entrySet. It is significant when using Map.copyOf on large maps.
Map.copyOf first creates a temporary array of entries before calling Map.ofEntries.
Then Map.ofEntries creates another temporary array of objects before calling ImmutableCollections.MapN.
Finally ImmutableCollections.MapN constructor creates the final object array (table field).
By simply having another constructor for ImmutableCollections.MapN taking a Set<Map.Entry> as parameter, the two temporary arrays creation/copy could be avoided. Map.copyOf could directly call ImmutableCollections.MapN with map.entrySet. It is significant when using Map.copyOf on large maps.