--- jsr166/src/main/java/util/HashMap.java 2018/05/22 16:16:57 1.5
+++ jsr166/src/main/java/util/HashMap.java 2018/12/18 20:21:24 1.10
@@ -34,7 +34,7 @@ import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
-import jdk.internal.misc.SharedSecrets;
+// OPENJDK import jdk.internal.access.SharedSecrets;
/**
* Hash table based implementation of the {@code Map} interface. This
@@ -118,7 +118,7 @@ import jdk.internal.misc.SharedSecrets;
* should be used only to detect bugs.
*
*
This class is a member of the
- *
+ *
* Java Collections Framework.
*
* @param the type of keys maintained by this map
@@ -501,9 +501,14 @@ public class HashMap extends Abstra
(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();
@@ -1263,9 +1268,7 @@ public class HashMap extends Abstra
@Override
public V merge(K key, V value,
BiFunction super V, ? super V, ? extends V> remappingFunction) {
- if (value == null)
- throw new NullPointerException();
- if (remappingFunction == null)
+ if (value == null || remappingFunction == null)
throw new NullPointerException();
int hash = hash(key);
Node[] tab; Node first; int n, i;
@@ -1308,8 +1311,7 @@ public class HashMap extends Abstra
else
removeNode(hash, key, null, false, true);
return v;
- }
- if (value != null) {
+ } else {
if (t != null)
t.putTreeVal(this, tab, hash, key, value);
else {
@@ -1320,8 +1322,8 @@ public class HashMap extends Abstra
++modCount;
++size;
afterNodeInsertion(true);
+ return value;
}
- return value;
}
@Override
@@ -1447,7 +1449,7 @@ public class HashMap extends Abstra
// Check Map.Entry[].class since it's the nearest public type to
// what we're actually creating.
- SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Map.Entry[].class, cap);
+ jsr166.Platform.checkArray(s, Map.Entry[].class, cap);
@SuppressWarnings({"rawtypes","unchecked"})
Node[] tab = (Node[])new Node[cap];
table = tab;
@@ -2148,7 +2150,7 @@ public class HashMap extends Abstra
if (replacement != p) {
TreeNode pp = replacement.parent = p.parent;
if (pp == null)
- root = replacement;
+ (root = replacement).red = false;
else if (p == pp.left)
pp.left = replacement;
else