diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2011-05-04 14:36:42 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2011-05-04 14:36:42 +0000 |
commit | 00f6d557ed23f18868b85bd23c790ffd5c044867 (patch) | |
tree | 6aec508b4a2ca6d6f9a3df370ef363e7884c3387 /src | |
parent | e573f9b206f5822dce5f9ce86c5d680a5538cf90 (diff) | |
download | scala-00f6d557ed23f18868b85bd23c790ffd5c044867.tar.gz scala-00f6d557ed23f18868b85bd23c790ffd5c044867.tar.bz2 scala-00f6d557ed23f18868b85bd23c790ffd5c044867.zip |
Fixes and closes #4535.
No review.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/mutable/ArrayStack.scala | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/library/scala/collection/mutable/ArrayStack.scala b/src/library/scala/collection/mutable/ArrayStack.scala index 012105d7c4..b39aff2463 100644 --- a/src/library/scala/collection/mutable/ArrayStack.scala +++ b/src/library/scala/collection/mutable/ArrayStack.scala @@ -169,7 +169,22 @@ extends Seq[T] */ def +=(x: T): this.type = { push(x); this } - def result = new ArrayStack[T](table.reverse, index) + def result = { + reverseTable() + this + } + + private def reverseTable() { + var i = 0 + val until = index / 2 + while (i < until) { + val revi = index - i - 1 + val tmp = table(i) + table(i) = table(revi) + table(revi) = tmp + i += 1 + } + } /** Pop the top two elements off the stack, apply `f` to them and push the result * back on to the stack. |