Skip to content

Commit 60cdb31

Browse files
committed
SI-9407 Vector implementation bit-shift bugfix
Fixed logically incorrect or unnecessary code in Vector as reported by Dirk Toewe. No tests. Because of the size of the vectors, tests would be impractically slow. Also, the logic is quite clear: when you are recursing through a tree, using the wrong bit shift means you hit the wrong part of the tree, and when you create and then always overwrite a mutable var, you should just not do it to begin with.
1 parent 6426d0b commit 60cdb31

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

src/library/scala/collection/immutable/Vector.scala

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,8 +1156,6 @@ private[immutable] trait VectorPointer[T] {
11561156
if (depth == 3) {
11571157
display3 = new Array(32)
11581158
display3((oldIndex >> 15) & 31) = display2
1159-
display2 = new Array(32)
1160-
display1 = new Array(32)
11611159
depth +=1
11621160
}
11631161
display2 = display3((newIndex >> 15) & 31).asInstanceOf[Array[AnyRef]]
@@ -1170,9 +1168,6 @@ private[immutable] trait VectorPointer[T] {
11701168
if (depth == 4) {
11711169
display4 = new Array(32)
11721170
display4((oldIndex >> 20) & 31) = display3
1173-
display3 = new Array(32)
1174-
display2 = new Array(32)
1175-
display1 = new Array(32)
11761171
depth +=1
11771172
}
11781173
display3 = display4((newIndex >> 20) & 31).asInstanceOf[Array[AnyRef]]
@@ -1187,13 +1182,9 @@ private[immutable] trait VectorPointer[T] {
11871182
if (depth == 5) {
11881183
display5 = new Array(32)
11891184
display5((oldIndex >> 25) & 31) = display4
1190-
display4 = new Array(32)
1191-
display3 = new Array(32)
1192-
display2 = new Array(32)
1193-
display1 = new Array(32)
11941185
depth +=1
11951186
}
1196-
display4 = display5((newIndex >> 20) & 31).asInstanceOf[Array[AnyRef]]
1187+
display4 = display5((newIndex >> 25) & 31).asInstanceOf[Array[AnyRef]]
11971188
if (display4 == null) display4 = new Array(32)
11981189
display3 = display4((newIndex >> 20) & 31).asInstanceOf[Array[AnyRef]]
11991190
if (display3 == null) display3 = new Array(32)

0 commit comments

Comments
 (0)