Skip to content

Commit 9c7cd89

Browse files
committed
Use a LinkedHashSet to store keys in a strict KeySet
We need a data structure that both acts like a Set (queries membership efficiently), and has a stable iteration order. LinkedHashSet seems to fit this criteria.
1 parent 8f9fddf commit 9c7cd89

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

library/src/scala/collection/Map.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ transparent trait MapOps[K, +V, +CC[_, _] <: IterableOps[?, AnyConstr, ?], +C]
216216
*/
217217
protected trait GenKeySet { this: Set[K] =>
218218
// CC note: this is unavoidable to make the KeySet pure.
219-
private[MapOps] val allKeys = MapOps.this.keysIterator.toList
219+
private[MapOps] val allKeys = MapOps.this.keysIterator.to(mutable.LinkedHashSet)
220220
// We restore the lazy behavior in LazyKeySet
221221
def iterator: Iterator[K] =
222222
allKeys.iterator

0 commit comments

Comments
 (0)