diff options
author | Adriaan Moors <adriaan@lightbend.com> | 2017-02-16 12:29:04 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-16 12:29:04 -0800 |
commit | 813324a8e733c11ed603de4597a7e9e34051eca9 (patch) | |
tree | 30147a1359f6d30e3373b5daa43dcf54a92e31ed /src/library/scala/collection | |
parent | e2be7c498dd849a007ab3e2a923fe48c8ae74b94 (diff) | |
parent | d1dbf1864c4853854701c1b0c51c0e5e21eda9d8 (diff) | |
download | scala-813324a8e733c11ed603de4597a7e9e34051eca9.tar.gz scala-813324a8e733c11ed603de4597a7e9e34051eca9.tar.bz2 scala-813324a8e733c11ed603de4597a7e9e34051eca9.zip |
Merge pull request #5687 from retronym/ticket/10177
SI-10177 Override lazy operations to preserve TrieMap's semantics
Diffstat (limited to 'src/library/scala/collection')
-rw-r--r-- | src/library/scala/collection/concurrent/TrieMap.scala | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/library/scala/collection/concurrent/TrieMap.scala b/src/library/scala/collection/concurrent/TrieMap.scala index 769d7b0dac..fe0b5c4f0e 100644 --- a/src/library/scala/collection/concurrent/TrieMap.scala +++ b/src/library/scala/collection/concurrent/TrieMap.scala @@ -932,6 +932,33 @@ extends scala.collection.concurrent.Map[K, V] if (nonReadOnly) readOnlySnapshot().iterator else new TrieMapIterator(0, this) + //////////////////////////////////////////////////////////////////////////// + // + // SI-10177 These methods need overrides as the inherited implementations + // call `.iterator` more than once, which doesn't guarantee a coherent + // view of the data if there is a concurrent writer + // Note that the we don't need overrides for keysIterator or valuesIterator + // TrieMapTest validates the behaviour. + override def values: Iterable[V] = { + if (nonReadOnly) readOnlySnapshot().values + else super.values + } + override def keySet: Set[K] = { + if (nonReadOnly) readOnlySnapshot().keySet + else super.keySet + } + override def filterKeys(p: K => Boolean): collection.Map[K, V] = { + if (nonReadOnly) readOnlySnapshot().filterKeys(p) + else super.filterKeys(p) + } + override def mapValues[W](f: V => W): collection.Map[K, W] = { + if (nonReadOnly) readOnlySnapshot().mapValues(f) + else super.mapValues(f) + } + // END extra overrides + /////////////////////////////////////////////////////////////////// + + private def cachedSize() = { val r = RDCSS_READ_ROOT() r.cachedSize(this) |