File tree 2 files changed +16
-4
lines changed
main/scala/scala/collection/decorators
test/scala/scala/collection/decorators 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -44,8 +44,13 @@ class BitSetDecorator[+C <: BitSet with BitSetOps[C]](protected val bs: C) {
44
44
val bitOffset = shiftBy & WordMask
45
45
val wordOffset = shiftBy >>> LogWL
46
46
47
+ var significantWordCount = bs.nwords
48
+ while (significantWordCount > 0 && bs.word(significantWordCount - 1 ) == 0 ) {
49
+ significantWordCount -= 1
50
+ }
51
+
47
52
if (bitOffset == 0 ) {
48
- val newSize = bs.nwords + wordOffset
53
+ val newSize = significantWordCount + wordOffset
49
54
require(newSize <= MaxSize )
50
55
val newBits = Array .ofDim[Long ](newSize)
51
56
var i = wordOffset
@@ -56,14 +61,14 @@ class BitSetDecorator[+C <: BitSet with BitSetOps[C]](protected val bs: C) {
56
61
newBits
57
62
} else {
58
63
val revBitOffset = WordLength - bitOffset
59
- val extraBits = bs.word(bs.nwords - 1 ) >>> revBitOffset
64
+ val extraBits = bs.word(significantWordCount - 1 ) >>> revBitOffset
60
65
val extraWordCount = if (extraBits == 0 ) 0 else 1
61
- val newSize = bs.nwords + wordOffset + extraWordCount
66
+ val newSize = significantWordCount + wordOffset + extraWordCount
62
67
require(newSize <= MaxSize )
63
68
val newBits = Array .ofDim[Long ](newSize)
64
69
var previous = 0L
65
70
var i = 0
66
- while (i < bs.nwords ) {
71
+ while (i < significantWordCount ) {
67
72
val current = bs.word(i)
68
73
newBits(i + wordOffset) = (previous >>> revBitOffset) | (current << bitOffset)
69
74
previous = current
Original file line number Diff line number Diff line change @@ -36,6 +36,13 @@ class BitSetDecoratorTest {
36
36
}
37
37
}
38
38
39
+ @ Test
40
+ def skipZeroWordsOnShiftLeft (): Unit = {
41
+ val result = BitSet (5 * 64 - 1 ) << 64
42
+ assertEquals(BitSet (6 * 64 - 1 ), result)
43
+ assertEquals(6 , result.nwords)
44
+ }
45
+
39
46
@ Test
40
47
def shiftEmptyRight (): Unit = {
41
48
for (shiftBy <- 0 to 128 ) {
You can’t perform that action at this time.
0 commit comments