mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8210280: Unnecessary reallocation when invoking HashMap.putAll()
Co-authored-by: Michal Vala <mvala@redhat.com> Co-authored-by: Martin Buchholz <martinrb@google.com> Reviewed-by: martin, mvala, igerasim, chegar, rriggs
This commit is contained in:
parent
1f230335e2
commit
f0807ebc18
6 changed files with 343 additions and 2 deletions
|
@ -501,9 +501,14 @@ public class HashMap<K,V> extends AbstractMap<K,V>
|
|||
(int)ft : MAXIMUM_CAPACITY);
|
||||
if (t > threshold)
|
||||
threshold = tableSizeFor(t);
|
||||
} else {
|
||||
// Because of linked-list bucket constraints, we cannot
|
||||
// expand all at once, but can reduce total resize
|
||||
// effort by repeated doubling now vs later
|
||||
while (s > threshold && table.length < MAXIMUM_CAPACITY)
|
||||
resize();
|
||||
}
|
||||
else if (s > threshold)
|
||||
resize();
|
||||
|
||||
for (Map.Entry<? extends K, ? extends V> e : m.entrySet()) {
|
||||
K key = e.getKey();
|
||||
V value = e.getValue();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue