diff options
author | Philipp Haller <hallerp@gmail.com> | 2009-11-05 21:20:26 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2009-11-05 21:20:26 +0000 |
commit | 72ede3ed81cbdd53c6f8222227617ace4dc99fd0 (patch) | |
tree | de3ebe66998dea5dd719ba50f20964548962301f | |
parent | 679d4590d96b896d24c7ae75ef1afdab02c78c31 (diff) | |
download | scala-72ede3ed81cbdd53c6f8222227617ace4dc99fd0.tar.gz scala-72ede3ed81cbdd53c6f8222227617ace4dc99fd0.tar.bz2 scala-72ede3ed81cbdd53c6f8222227617ace4dc99fd0.zip |
Replaced immutable.Queue.apply, which should fi...
Replaced immutable.Queue.apply, which should fix the build.
-rw-r--r-- | src/library/scala/collection/immutable/Queue.scala | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/library/scala/collection/immutable/Queue.scala b/src/library/scala/collection/immutable/Queue.scala index 2d5b05778b..079c3f3a3d 100644 --- a/src/library/scala/collection/immutable/Queue.scala +++ b/src/library/scala/collection/immutable/Queue.scala @@ -40,17 +40,13 @@ class Queue[+A] protected( * @throws Predef.NoSuchElementException if the queue is too short. */ def apply(n: Int): A = { - @tailrec - def walk(i: Int, inlist: List[A], outlist: List[A]): A = - (i == 0, inlist.isEmpty, outlist.isEmpty) match { - case (_, true, true) => throw new NoSuchElementException("index out of range") - case (true, _, false) => outlist.head - case (true, _, true) => inlist.last - case (false, _, false) => walk(i - 1, inlist, outlist.tail) - case (false, false, true) => walk(i - 1, Nil, inlist.reverse.tail) - } - - walk(n, in, out) + val len = out.length + if (n < len) out.apply(n) + else { + val m = n - len + if (m < in.length) in.reverse.apply(m) + else throw new NoSuchElementException("index out of range") + } } /** Returns the elements in the list as an iterator |