diff options
author | Daniel Dietrich <daniel.dietrich@gmx.net> | 2015-06-02 23:21:57 +0200 |
---|---|---|
committer | Daniel Dietrich <daniel.dietrich@gmx.net> | 2015-06-02 23:21:57 +0200 |
commit | 3667df14ff8c5a5866d3dee0c9857ef038e05d72 (patch) | |
tree | 08a4e512e9bd8a103b7dde66abf308fa081d979b /src | |
parent | 70f0b1ded880ec9b3a9478d02f1898fcfeee230c (diff) | |
download | scala-3667df14ff8c5a5866d3dee0c9857ef038e05d72.tar.gz scala-3667df14ff8c5a5866d3dee0c9857ef038e05d72.tar.bz2 scala-3667df14ff8c5a5866d3dee0c9857ef038e05d72.zip |
Applying inverse index instead of reversing a List
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/immutable/Queue.scala | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/library/scala/collection/immutable/Queue.scala b/src/library/scala/collection/immutable/Queue.scala index 98266716cc..e40ebdbe71 100644 --- a/src/library/scala/collection/immutable/Queue.scala +++ b/src/library/scala/collection/immutable/Queue.scala @@ -60,7 +60,8 @@ class Queue[+A] protected(protected val in: List[A], protected val out: List[A]) if (n < len) out.apply(n) else { val m = n - len - if (m < in.length) in.reverse.apply(m) + val l = in.length + if (m < l) in.apply(l - m - 1) else throw new NoSuchElementException("index out of range") } } |