Skip to content

Commit 8c5867e

Browse files
committed
[11049] Instead of catching thrown exception in IndexSeqViewIterator, proactively throw if the iterator is empty
1 parent aa3607c commit 8c5867e

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

library/src/scala/collection/IndexedSeqView.scala

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ object IndexedSeqView {
2626
private[this] var current = 0
2727
override def knownSize: Int = self.size - current
2828
def hasNext = current < self.size
29-
def next(): A = try {
30-
val r = self.apply(current)
31-
current += 1
32-
r
33-
} catch {
34-
case _: IndexOutOfBoundsException => throw new NoSuchElementException("last of empty iterator")
35-
}
29+
def next(): A =
30+
if (hasNext) {
31+
val r = self.apply(current)
32+
current += 1
33+
r
34+
} else Iterator.empty.next()
3635
}
3736

3837
/** An `IndexedSeqOps` whose collection type and collection type constructor are unknown */

0 commit comments

Comments
 (0)