Skip to content

Commit dd9400f

Browse files
authored
Merge pull request scala/scala#8959 from retronym/topic/vector-empty-iterator
2 parents cb0c998 + 8f0d5b2 commit dd9400f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ object Vector extends IndexedSeqFactory[Vector] {
3131
// Constants governing concat strategy for performance
3232
private final val Log2ConcatFaster = 5
3333
private final val TinyAppendFaster = 2
34+
private val emptyIterator: VectorIterator[Nothing] = new VectorIterator[Nothing](0, 0)
3435
}
3536

3637
// in principle, most members should be private. however, access privileges must
@@ -94,9 +95,12 @@ extends AbstractSeq[A]
9495
}
9596

9697
override def iterator: VectorIterator[A] = {
97-
val s = new VectorIterator[A](startIndex, endIndex)
98-
initIterator(s)
99-
s
98+
if (length == 0) Vector.emptyIterator
99+
else {
100+
val s = new VectorIterator[A](startIndex, endIndex)
101+
initIterator(s)
102+
s
103+
}
100104
}
101105

102106
override /*SeqLike*/

0 commit comments

Comments
 (0)