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 | |
parent | e573f9b206f5822dce5f9ce86c5d680a5538cf90 (diff) | |
download | scala-00f6d557ed23f18868b85bd23c790ffd5c044867.tar.gz scala-00f6d557ed23f18868b85bd23c790ffd5c044867.tar.bz2 scala-00f6d557ed23f18868b85bd23c790ffd5c044867.zip |
Fixes and closes #4535.
No review.
-rw-r--r-- | src/library/scala/collection/mutable/ArrayStack.scala | 17 | ||||
-rw-r--r-- | test/files/run/t4535.check | 3 | ||||
-rw-r--r-- | test/files/run/t4535.scala | 30 |
3 files changed, 49 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. diff --git a/test/files/run/t4535.check b/test/files/run/t4535.check new file mode 100644 index 0000000000..9d4ce0d535 --- /dev/null +++ b/test/files/run/t4535.check @@ -0,0 +1,3 @@ +ArrayStack(1, 2, 3) +ArrayStack(1, 2, 3, 4, 5, 6) +ArrayStack(6, 5, 4, 3, 2, 1)
\ No newline at end of file diff --git a/test/files/run/t4535.scala b/test/files/run/t4535.scala new file mode 100644 index 0000000000..91c13a28cd --- /dev/null +++ b/test/files/run/t4535.scala @@ -0,0 +1,30 @@ + + +import collection._ + + +// #4535 +object Test { + + def main(args: Array[String]) { + val as = new mutable.ArrayStack[Int] + as push 1 + as push 2 + as push 3 + println(as.reverse) + + as push 4 + as push 5 + as push 6 + println(as.reverse) + + println(as map { x => x }) + + for (i <- 0 until 100) { + as push i + assert(as == as.map(x => x)) + assert(as == as.reverse.reverse) + } + } + +} |