Skip to content

Commit 3a5ccd6

Browse files
authored
Merge pull request scala/scala#7004 from joshlemer/issue/11049-2.13
[11049] Fixes scala/bug#11049
2 parents 1fc9f07 + 8c5867e commit 3a5ccd6

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

library/src/scala/collection/IndexedSeqView.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +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 = {
30-
val r = self.apply(current)
31-
current += 1
32-
r
33-
}
29+
def next(): A =
30+
if (hasNext) {
31+
val r = self.apply(current)
32+
current += 1
33+
r
34+
} else Iterator.empty.next()
3435
}
3536

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

library/src/scala/collection/mutable/ArrayBuffer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ object ArrayBuffer extends StrictOptimizedSeqFactory[ArrayBuffer] {
209209

210210
final class ArrayBufferView[A](val array: Array[AnyRef], val length: Int) extends AbstractIndexedSeqView[A] {
211211
@throws[ArrayIndexOutOfBoundsException]
212-
def apply(n: Int) = array(n).asInstanceOf[A]
212+
def apply(n: Int) = if (n < length) array(n).asInstanceOf[A] else throw new IndexOutOfBoundsException(n.toString)
213213
override protected[this] def className = "ArrayBufferView"
214214
}
215215

library/src/scala/collection/mutable/PriorityQueue.scala

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,7 @@ sealed class PriorityQueue[A](implicit val ord: Ordering[A])
247247
*
248248
* @return an iterator over all the elements.
249249
*/
250-
override def iterator: Iterator[A] = new AbstractIterator[A] {
251-
private[this] var i = 1
252-
def hasNext: Boolean = i < resarr.p_size0
253-
def next(): A = {
254-
val n = resarr.p_array(i)
255-
i += 1
256-
toA(n)
257-
}
258-
}
250+
override def iterator: Iterator[A] = resarr.iterator.drop(1)
259251

260252
/** Returns the reverse of this priority queue. The new priority queue has
261253
* the same elements as the original, but the opposite ordering.

0 commit comments

Comments
 (0)