diff options
author | Paul Phillips <paulp@improving.org> | 2010-01-18 04:14:25 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-01-18 04:14:25 +0000 |
commit | d73a32db9cb0357cb365b78bdbd0fa8d6af9873c (patch) | |
tree | c2fb02af2ce89f94d75c285a5b30a86b260be600 /src/library | |
parent | 518ac3d5fd113e24df9cba5383a0bc9641b41f1d (diff) | |
download | scala-d73a32db9cb0357cb365b78bdbd0fa8d6af9873c.tar.gz scala-d73a32db9cb0357cb365b78bdbd0fa8d6af9873c.tar.bz2 scala-d73a32db9cb0357cb365b78bdbd0fa8d6af9873c.zip |
Fix and test case for #408. Review by community.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/collection/immutable/HashSet.scala | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/library/scala/collection/immutable/HashSet.scala b/src/library/scala/collection/immutable/HashSet.scala index 25a8059b0c..2320187be9 100644 --- a/src/library/scala/collection/immutable/HashSet.scala +++ b/src/library/scala/collection/immutable/HashSet.scala @@ -115,17 +115,20 @@ class HashSet[A] extends Set[A] private def makeCopy(last: HashSet[A]) { def undo(m: HashSet[A]) { - if (m ne last) { - undo(m.later) - if (m.deleted) addEntry(m.changedElem) - else removeEntry(m.changedElem) - } + if (m.deleted) addEntry(m.changedElem) + else removeEntry(m.changedElem) } table = new scala.Array[AnyRef](last.table.length) scala.Array.copy(last.table, 0, table, 0, table.length) tableSize = last.tableSize threshold = last.threshold - undo(this) + + // we need to work from the end of the list but non-tail-recursion + // potentially blows the stack, so instead we create a stack on the heap. + // See ticket #408. + val toUndo = new mutable.Stack[HashSet[A]] + toUndo pushAll ((Iterator iterate this)(_.later) takeWhile (_ ne last)) + toUndo foreach undo later = null } |