File tree 2 files changed +8
-6
lines changed
main/scala/scala/collection/decorators
test/scala/scala/collection/decorators
2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,8 @@ class BitSetDecorator[+C <: BitSet with BitSetOps[C]](protected val bs: C) {
15
15
*/
16
16
def << (shiftBy : Int ): C = {
17
17
18
- val shiftedBits = if (shiftBy > 0 ) shiftLeft(shiftBy)
18
+ val shiftedBits = if (bs.nwords == 0 || bs.nwords == 1 && bs.word(0 ) == 0 ) Array .emptyLongArray
19
+ else if (shiftBy > 0 ) shiftLeft(shiftBy)
19
20
else if (shiftBy == 0 ) bs.toBitMask
20
21
else shiftRight(- shiftBy)
21
22
@@ -30,7 +31,8 @@ class BitSetDecorator[+C <: BitSet with BitSetOps[C]](protected val bs: C) {
30
31
*/
31
32
def >> (shiftBy : Int ): C = {
32
33
33
- val shiftedBits = if (shiftBy > 0 ) shiftRight(shiftBy)
34
+ val shiftedBits = if (bs.nwords == 0 || bs.nwords == 1 && bs.word(0 ) == 0 ) Array .emptyLongArray
35
+ else if (shiftBy > 0 ) shiftRight(shiftBy)
34
36
else if (shiftBy == 0 ) bs.toBitMask
35
37
else shiftLeft(- shiftBy)
36
38
Original file line number Diff line number Diff line change @@ -6,13 +6,13 @@ import scala.collection.BitSet
6
6
7
7
class BitSetDecoratorTest {
8
8
9
- import Assert .assertEquals
9
+ import Assert .{ assertEquals , assertSame }
10
10
import BitSet .empty
11
11
12
12
@ Test
13
13
def shiftEmptyLeft (): Unit = {
14
14
for (shiftBy <- 0 to 128 ) {
15
- assertEquals (empty, empty << shiftBy)
15
+ assertSame (empty, empty << shiftBy)
16
16
}
17
17
}
18
18
@@ -39,15 +39,15 @@ class BitSetDecoratorTest {
39
39
@ Test
40
40
def shiftEmptyRight (): Unit = {
41
41
for (shiftBy <- 0 to 128 ) {
42
- assertEquals (empty, empty >> shiftBy)
42
+ assertSame (empty, empty >> shiftBy)
43
43
}
44
44
}
45
45
46
46
@ Test
47
47
def shiftLowestBitRight (): Unit = {
48
48
assertEquals(BitSet (0 ), BitSet (0 ) >> 0 )
49
49
for (shiftBy <- 1 to 128 ) {
50
- assertEquals (empty, BitSet (0 ) >> shiftBy)
50
+ assertSame (empty, BitSet (0 ) >> shiftBy)
51
51
}
52
52
}
53
53
You can’t perform that action at this time.
0 commit comments