File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
src/library/scala/collection/immutable
test/junit/scala/collection/immutable Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -86,10 +86,14 @@ final class Vector[+A] private[immutable] (private[collection] val startIndex: I
86
86
if (s.depth > 1 ) s.gotoPos(startIndex, startIndex ^ focus)
87
87
}
88
88
89
- override def iterator : VectorIterator [A ] = {
90
- val s = new VectorIterator [A ](startIndex, endIndex)
91
- initIterator(s)
92
- s
89
+ override def iterator : Iterator [A ] = {
90
+ if (isEmpty)
91
+ Iterator .empty
92
+ else {
93
+ val s = new VectorIterator [A ](startIndex, endIndex)
94
+ initIterator(s)
95
+ s
96
+ }
93
97
}
94
98
95
99
// Ideally, clients will inline calls to map all the way down, including the iterator/builder methods.
Original file line number Diff line number Diff line change @@ -50,4 +50,10 @@ class VectorTest {
50
50
}
51
51
52
52
@ Test def checkSearch : Unit = SeqTests .checkSearch(Vector (0 to 1000 : _* ), 15 , implicitly[Ordering [Int ]])
53
+
54
+ @ Test
55
+ def emptyIteratorReuse (): Unit = {
56
+ assertSame(Vector .empty.iterator, Vector .empty.iterator)
57
+ assertSame(Vector .empty.iterator, Vector (1 ).drop(1 ).iterator)
58
+ }
53
59
}
You can’t perform that action at this time.
0 commit comments