diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-06-07 07:38:14 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-06-07 07:38:14 +0200 |
commit | 10a746551dce2ec61f52be74bbd3a476a3068568 (patch) | |
tree | 364b771344c410dc37553f058b99e0f2b703fffd /src | |
parent | 6d0a498bab3aaff4747434fbfb5e17c8b26d676d (diff) | |
parent | c834fc2634d621599602fad3d9036df382975f9b (diff) | |
download | scala-10a746551dce2ec61f52be74bbd3a476a3068568.tar.gz scala-10a746551dce2ec61f52be74bbd3a476a3068568.tar.bz2 scala-10a746551dce2ec61f52be74bbd3a476a3068568.zip |
Merge pull request #4536 from danieldietrich/2.11.x
Applying inverse index instead of reversing a List
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/immutable/Queue.scala | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/library/scala/collection/immutable/Queue.scala b/src/library/scala/collection/immutable/Queue.scala index 98266716cc..53af3ce158 100644 --- a/src/library/scala/collection/immutable/Queue.scala +++ b/src/library/scala/collection/immutable/Queue.scala @@ -56,11 +56,12 @@ class Queue[+A] protected(protected val in: List[A], protected val out: List[A]) * @throws java.util.NoSuchElementException if the queue is too short. */ override def apply(n: Int): A = { - val len = out.length - if (n < len) out.apply(n) + val olen = out.length + if (n < olen) out.apply(n) else { - val m = n - len - if (m < in.length) in.reverse.apply(m) + val m = n - olen + val ilen = in.length + if (m < ilen) in.apply(ilen - m - 1) else throw new NoSuchElementException("index out of range") } } |