From 6b13a1ddd27bafbca78cd402e83ea72718e0d92f Mon Sep 17 00:00:00 2001 From: Rajiv Date: Mon, 11 Nov 2013 11:46:32 -0800 Subject: Use an intrinsic for the next power of two calculation and also return the input as is if it is already a power of two --- src/library/scala/collection/mutable/OpenHashMap.scala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/library/scala/collection/mutable/OpenHashMap.scala b/src/library/scala/collection/mutable/OpenHashMap.scala index 7d522d1e6e..aade2ed6fb 100644 --- a/src/library/scala/collection/mutable/OpenHashMap.scala +++ b/src/library/scala/collection/mutable/OpenHashMap.scala @@ -17,7 +17,6 @@ package mutable * @since 2.7 */ object OpenHashMap { - import generic.BitOperations.Int.highestOneBit def apply[K, V](elems : (K, V)*) = new OpenHashMap[K, V] ++= elems def empty[K, V] = new OpenHashMap[K, V] @@ -27,7 +26,7 @@ object OpenHashMap { var value: Option[Value]) extends HashEntry[Key, OpenEntry[Key, Value]] - private[mutable] def nextPowerOfTwo(i : Int) = highestOneBit(i) << 1 + private[mutable] def nextPositivePowerOfTwo(i : Int) = 1 << (32 - Integer.numberOfLeadingZeros(i - 1)) } /** A mutable hash map based on an open hashing scheme. The precise scheme is @@ -62,7 +61,7 @@ extends AbstractMap[Key, Value] override def empty: OpenHashMap[Key, Value] = OpenHashMap.empty[Key, Value] - private[this] val actualInitialSize = OpenHashMap.nextPowerOfTwo(initialSize) + private[this] val actualInitialSize = OpenHashMap.nextPositivePowerOfTwo(initialSize) private var mask = actualInitialSize - 1 private var table : Array[Entry] = new Array[Entry](actualInitialSize) -- cgit v1.2.3