Skip to content

Commit

Permalink
Fix for si-5590.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandar Prokopec committed May 4, 2012
1 parent f146d58 commit b2c3f87
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/library/scala/collection/mutable/HashTable.scala
Expand Up @@ -187,7 +187,7 @@ trait HashTable[A, Entry >: Null <: HashEntry[A, Entry]] extends HashTable.HashU
}

/** Avoid iterator for a 2x faster traversal. */
protected final def foreachEntry[C](f: Entry => C) {
protected def foreachEntry[C](f: Entry => C) {
val iterTable = table
var idx = lastPopulatedIndex
var es = iterTable(idx)
Expand Down
8 changes: 8 additions & 0 deletions src/library/scala/collection/mutable/LinkedHashMap.scala
Expand Up @@ -132,6 +132,14 @@ class LinkedHashMap[A, B] extends AbstractMap[A, B]
}
}

protected override def foreachEntry[C](f: Entry => C) {
var cur = firstEntry
while (cur ne null) {
f(cur)
cur = cur.later
}
}

override def clear() {
clearTable()
firstEntry = null
Expand Down
4 changes: 4 additions & 0 deletions test/files/run/t5590.check
@@ -0,0 +1,4 @@
Map(a -> a, b -> b, c -> c)
Map(a -> a, b -> b, c -> c)
Set(a, b, c, d, e)
Set(a, b, c, d, e)
31 changes: 31 additions & 0 deletions test/files/run/t5590.scala
@@ -0,0 +1,31 @@



import java.io._
import collection._



object Test {

def check(obj: AnyRef) {
println(obj)

val bos = new ByteArrayOutputStream()
val out = new ObjectOutputStream(bos)
out.writeObject(obj)
val arr = bos.toByteArray()
val in = new ObjectInputStream(new ByteArrayInputStream(arr))
val deser = in.readObject()

println(deser)
}

def main(args: Array[String]) {
val lhm = mutable.LinkedHashMap("a" -> "a", "b" -> "b", "c" -> "c")
val lhs = mutable.LinkedHashSet("a", "b", "c", "d", "e")
check(lhm)
check(lhs)
}

}

0 comments on commit b2c3f87

Please sign in to comment.