7192942: (coll) Inefficient calculation of power of two in HashMap
authorigerasim
Tue, 30 Jul 2013 21:11:08 +0400
changeset 19184 927725c23203
parent 19183 13ac55f786e3
child 19185 34aa83720203
7192942: (coll) Inefficient calculation of power of two in HashMap Reviewed-by: mduigou
jdk/src/share/classes/java/util/HashMap.java
--- a/jdk/src/share/classes/java/util/HashMap.java	Thu Aug 01 12:38:07 2013 +0100
+++ b/jdk/src/share/classes/java/util/HashMap.java	Tue Jul 30 21:11:08 2013 +0400
@@ -876,13 +876,9 @@
 
     private static int roundUpToPowerOf2(int number) {
         // assert number >= 0 : "number must be non-negative";
-        int rounded = number >= MAXIMUM_CAPACITY
+        return number >= MAXIMUM_CAPACITY
                 ? MAXIMUM_CAPACITY
-                : (rounded = Integer.highestOneBit(number)) != 0
-                    ? (Integer.bitCount(number) > 1) ? rounded << 1 : rounded
-                    : 1;
-
-        return rounded;
+                : (number > 1) ? Integer.highestOneBit((number - 1) << 1) : 1;
     }
 
     /**