ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/HashMap.java
(Generate patch)

Comparing jsr166/src/main/java/util/HashMap.java (file contents):
Revision 1.4 by jsr166, Wed Mar 28 02:50:41 2018 UTC vs.
Revision 1.10 by jsr166, Tue Dec 18 20:21:24 2018 UTC

# Line 34 | Line 34 | import java.util.function.BiConsumer;
34   import java.util.function.BiFunction;
35   import java.util.function.Consumer;
36   import java.util.function.Function;
37 < import jdk.internal.misc.SharedSecrets;
37 > // OPENJDK import jdk.internal.access.SharedSecrets;
38  
39   /**
40   * Hash table based implementation of the {@code Map} interface.  This
# Line 118 | Line 118 | import jdk.internal.misc.SharedSecrets;
118   * should be used only to detect bugs.</i>
119   *
120   * <p>This class is a member of the
121 < * <a href="{@docRoot}/java/util/package-summary.html#CollectionsFramework">
121 > * <a href="{@docRoot}/java.base/java/util/package-summary.html#CollectionsFramework">
122   * Java Collections Framework</a>.
123   *
124   * @param <K> the type of keys maintained by this map
# Line 376 | Line 376 | public class HashMap<K,V> extends Abstra
376       * Returns a power of two size for the given target capacity.
377       */
378      static final int tableSizeFor(int cap) {
379 <        int n = cap - 1;
380 <        n |= n >>> 1;
381 <        n |= n >>> 2;
382 <        n |= n >>> 4;
383 <        n |= n >>> 8;
384 <        n |= n >>> 16;
379 >        int n = -1 >>> Integer.numberOfLeadingZeros(cap - 1);
380          return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
381      }
382  
# Line 506 | Line 501 | public class HashMap<K,V> extends Abstra
501                           (int)ft : MAXIMUM_CAPACITY);
502                  if (t > threshold)
503                      threshold = tableSizeFor(t);
504 +            } else {
505 +                // Because of linked-list bucket constraints, we cannot
506 +                // expand all at once, but can reduce total resize
507 +                // effort by repeated doubling now vs later
508 +                while (s > threshold && table.length < MAXIMUM_CAPACITY)
509 +                    resize();
510              }
511 <            else if (s > threshold)
511 <                resize();
511 >
512              for (Map.Entry<? extends K, ? extends V> e : m.entrySet()) {
513                  K key = e.getKey();
514                  V value = e.getValue();
# Line 1268 | Line 1268 | public class HashMap<K,V> extends Abstra
1268      @Override
1269      public V merge(K key, V value,
1270                     BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
1271 <        if (value == null)
1272 <            throw new NullPointerException();
1273 <        if (remappingFunction == null)
1271 >        if (value == null || remappingFunction == null)
1272              throw new NullPointerException();
1273          int hash = hash(key);
1274          Node<K,V>[] tab; Node<K,V> first; int n, i;
# Line 1313 | Line 1311 | public class HashMap<K,V> extends Abstra
1311              else
1312                  removeNode(hash, key, null, false, true);
1313              return v;
1314 <        }
1317 <        if (value != null) {
1314 >        } else {
1315              if (t != null)
1316                  t.putTreeVal(this, tab, hash, key, value);
1317              else {
# Line 1325 | Line 1322 | public class HashMap<K,V> extends Abstra
1322              ++modCount;
1323              ++size;
1324              afterNodeInsertion(true);
1325 +            return value;
1326          }
1329        return value;
1327      }
1328  
1329      @Override
# Line 1452 | Line 1449 | public class HashMap<K,V> extends Abstra
1449  
1450              // Check Map.Entry[].class since it's the nearest public type to
1451              // what we're actually creating.
1452 <            SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Map.Entry[].class, cap);
1452 >            jsr166.Platform.checkArray(s, Map.Entry[].class, cap);
1453              @SuppressWarnings({"rawtypes","unchecked"})
1454              Node<K,V>[] tab = (Node<K,V>[])new Node[cap];
1455              table = tab;
# Line 2153 | Line 2150 | public class HashMap<K,V> extends Abstra
2150              if (replacement != p) {
2151                  TreeNode<K,V> pp = replacement.parent = p.parent;
2152                  if (pp == null)
2153 <                    root = replacement;
2153 >                    (root = replacement).red = false;
2154                  else if (p == pp.left)
2155                      pp.left = replacement;
2156                  else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines