提交 bf632342 编写于 作者: I igerasim

7192942: (coll) Inefficient calculation of power of two in HashMap

Reviewed-by: mduigou
上级 aeafaa2a
......@@ -876,13 +876,9 @@ public class HashMap<K,V>
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;
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册