Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit 10a7465

Browse files
committed
Merge pull request scala#4536 from danieldietrich/2.11.x
Applying inverse index instead of reversing a List
2 parents 6d0a498 + c834fc2 commit 10a7465

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/library/scala/collection/immutable/Queue.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ class Queue[+A] protected(protected val in: List[A], protected val out: List[A])
5656
* @throws java.util.NoSuchElementException if the queue is too short.
5757
*/
5858
override def apply(n: Int): A = {
59-
val len = out.length
60-
if (n < len) out.apply(n)
59+
val olen = out.length
60+
if (n < olen) out.apply(n)
6161
else {
62-
val m = n - len
63-
if (m < in.length) in.reverse.apply(m)
62+
val m = n - olen
63+
val ilen = in.length
64+
if (m < ilen) in.apply(ilen - m - 1)
6465
else throw new NoSuchElementException("index out of range")
6566
}
6667
}

0 commit comments

Comments
 (0)