8000 [backport] Hash table getOrElseUpdate and indexing by adriaanm · Pull Request #5626 · scala/scala · GitHub
[go: up one dir, main page]

Skip to content

[backport] Hash table getOrElseUpdate and indexing #5626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 6, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
SI-8774 Null link fields in mutable hash maps on removal.
(cherry picked from commit 9a24860)
  • Loading branch information
Carsten Varming authored and adriaanm committed Jan 5, 2017
commit f31745ac9bc5d2fcad1ab52caf4a3b6169c7f9b4
5 changes: 4 additions & 1 deletion src/library/scala/collection/mutable/HashTable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ trait HashTable[A, Entry >: Null <: HashEntry[A, Entry]] extends HashTable.HashU
table(h) = e.next
tableSize = tableSize - 1
nnSizeMapRemove(h)
e.next = null
return e
} else {
var e1 = e.next
Expand All @@ -194,6 +195,7 @@ trait HashTable[A, Entry >: Null <: HashEntry[A, Entry]] extends HashTable.HashU
e.next = e1.next
tableSize = tableSize - 1
nnSizeMapRemove(h)
e1.next = null
return e1
}
}
Expand Down Expand Up @@ -227,8 +229,9 @@ trait HashTable[A, Entry >: Null <: HashEntry[A, Entry]] extends HashTable.HashU
var es = iterTable(idx)

while (es != null) {
val next = es.next // Cache next in case f removes es.
f(es.asInstanceOf[Entry])
es = es.next
es = next

while (es == null && idx > 0) {
idx -= 1
Expand Down
2 changes: 2 additions & 0 deletions src/library/scala/collection/mutable/LinkedHashMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class LinkedHashMap[A, B] extends AbstractMap[A, B]
else e.earlier.later = e.later
if (e.later eq null) lastEntry = e.earlier
else e.later.earlier = e.earlier
e.earlier = null // Null references to prevent nepotism
e.later = null
Some(e.value)
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/library/scala/collection/mutable/LinkedHashSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class LinkedHashSet[A] extends AbstractSet[A]
else e.earlier.later = e.later
if (e.later eq null) lastEntry = e.earlier
else e.later.earlier = e.earlier
e.earlier = null // Null references to prevent nepotism
e.later = null
true
}
}
Expand Down
0