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:
Doug Lea 2019-02-08 13:39:22 -08:00
parent 1f230335e2
commit f0807ebc18
6 changed files with 343 additions and 2 deletions

View file

@ -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();