diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2016-03-29 10:23:36 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2016-03-29 10:24:31 +1000 |
commit | 8b2e616c75026484fcfb75c4fdb50f2f94fda4e6 (patch) | |
tree | 440764fac59de07649530fc1027a6ee7896491f2 /src/library | |
parent | eb6e29d27eb9cac0430fb34c485788cf3108fe00 (diff) | |
download | scala-8b2e616c75026484fcfb75c4fdb50f2f94fda4e6.tar.gz scala-8b2e616c75026484fcfb75c4fdb50f2f94fda4e6.tar.bz2 scala-8b2e616c75026484fcfb75c4fdb50f2f94fda4e6.zip |
Use Java's highestOneBit, rather than our own versions.
The original code came from 2008, (a4ace382), at which point
we probably couldn't use JDK 1.5+ methods.
I haven't changed `unsignedCompare` yet to use the standard
library version, as it our version might have different
performance characteristics.
Background: http://www.drmaciver.com/2008/08/unsigned-comparison-in-javascala/
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/collection/generic/BitOperations.scala | 23 |
1 files changed, 2 insertions, 21 deletions
diff --git a/src/library/scala/collection/generic/BitOperations.scala b/src/library/scala/collection/generic/BitOperations.scala index d430ece2f5..2f460eee1f 100644 --- a/src/library/scala/collection/generic/BitOperations.scala +++ b/src/library/scala/collection/generic/BitOperations.scala @@ -26,16 +26,7 @@ private[collection] object BitOperations { def complement(i: Int) = (-1) ^ i def bits(num: Int) = 31 to 0 by -1 map (i => (num >>> i & 1) != 0) def bitString(num: Int, sep: String = "") = bits(num) map (b => if (b) "1" else "0") mkString sep - - def highestOneBit(j: Int) = { - var i = j - i |= (i >> 1) - i |= (i >> 2) - i |= (i >> 4) - i |= (i >> 8) - i |= (i >> 16) - i - (i >>> 1) - } + def highestOneBit(j: Int) = java.lang.Integer.highestOneBit(j) } object Int extends Int @@ -49,17 +40,7 @@ private[collection] object BitOperations { def complement(i: Long) = (-1L) ^ i def bits(num: Long) = 63L to 0L by -1L map (i => (num >>> i & 1L) != 0L) def bitString(num: Long, sep: String = "") = bits(num) map (b => if (b) "1" else "0") mkString sep - - def highestOneBit(j: Long) = { - var i = j - i |= (i >> 1) - i |= (i >> 2) - i |= (i >> 4) - i |= (i >> 8) - i |= (i >> 16) - i |= (i >> 32) - i - (i >>> 1) - } + def highestOneBit(j: Long) = java.lang.Long.highestOneBit(j) } object Long extends Long } |