changeset 6538:1afb03696eb7

7192942: (coll) Inefficient calculation of power of two in HashMap Reviewed-by: mduigou
author igerasim
date Tue, 13 Aug 2013 15:31:18 +0400
parents 36e578297fa7
children 8e7195ce61f1
files src/share/classes/java/util/HashMap.java
diffstat 1 files changed, 2 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/HashMap.java	Mon Aug 12 02:34:25 2013 -0700
+++ b/src/share/classes/java/util/HashMap.java	Tue Aug 13 15:31:18 2013 +0400
@@ -300,13 +300,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;
     }
 
     /**