summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/mutable/OpenHashMap.scala
diff options
context:
space:
mode:
authorRajiv <geetasen@gmail.com>2013-11-11 11:46:32 -0800
committerRajiv <geetasen@gmail.com>2013-11-11 18:44:30 -0800
commit6b13a1ddd27bafbca78cd402e83ea72718e0d92f (patch)
treecf7c7174596800c076800174fbd4597ffeb4c6c3 /src/library/scala/collection/mutable/OpenHashMap.scala
parentd2cee3a5e1d26ba27fd7912d48b1e7af0beb844a (diff)
downloadscala-6b13a1ddd27bafbca78cd402e83ea72718e0d92f.tar.gz
scala-6b13a1ddd27bafbca78cd402e83ea72718e0d92f.tar.bz2
scala-6b13a1ddd27bafbca78cd402e83ea72718e0d92f.zip
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
Diffstat (limited to 'src/library/scala/collection/mutable/OpenHashMap.scala')
-rw-r--r--src/library/scala/collection/mutable/OpenHashMap.scala5
1 files 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)