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.1 by jsr166, Wed Aug 23 05:33:00 2017 UTC vs.
Revision 1.5 by jsr166, Tue May 22 16:16:57 2018 UTC

# Line 1 | Line 1
1   /*
2 < * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
2 > * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4   *
5   * This code is free software; you can redistribute it and/or modify it
# 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;
38  
39   /**
40   * Hash table based implementation of the {@code Map} interface.  This
# Line 375 | 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;
379 <        n |= n >>> 1;
380 <        n |= n >>> 2;
381 <        n |= n >>> 4;
382 <        n |= n >>> 8;
383 <        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 1394 | Line 1390 | public class HashMap<K,V> extends Abstra
1390      }
1391  
1392      /**
1393 <     * Save the state of the {@code HashMap} instance to a stream (i.e.,
1398 <     * serialize it).
1393 >     * Saves this map to a stream (that is, serializes it).
1394       *
1395 +     * @param s the stream
1396 +     * @throws IOException if an I/O error occurs
1397       * @serialData The <i>capacity</i> of the HashMap (the length of the
1398       *             bucket array) is emitted (int), followed by the
1399       *             <i>size</i> (an int, the number of key-value
# Line 1415 | Line 1412 | public class HashMap<K,V> extends Abstra
1412      }
1413  
1414      /**
1415 <     * Reconstitute the {@code HashMap} instance from a stream (i.e.,
1416 <     * deserialize it).
1415 >     * Reconstitutes this map from a stream (that is, deserializes it).
1416 >     * @param s the stream
1417 >     * @throws ClassNotFoundException if the class of a serialized object
1418 >     *         could not be found
1419 >     * @throws IOException if an I/O error occurs
1420       */
1421      private void readObject(java.io.ObjectInputStream s)
1422          throws IOException, ClassNotFoundException {
# Line 1444 | Line 1444 | public class HashMap<K,V> extends Abstra
1444              float ft = (float)cap * lf;
1445              threshold = ((cap < MAXIMUM_CAPACITY && ft < MAXIMUM_CAPACITY) ?
1446                           (int)ft : Integer.MAX_VALUE);
1447 +
1448 +            // Check Map.Entry[].class since it's the nearest public type to
1449 +            // what we're actually creating.
1450 +            SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Map.Entry[].class, cap);
1451              @SuppressWarnings({"rawtypes","unchecked"})
1452              Node<K,V>[] tab = (Node<K,V>[])new Node[cap];
1453              table = tab;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines