diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2015-02-23 09:30:13 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2015-02-23 09:30:13 -0800 |
commit | 411530a846e4b424080a43e3b696830932e36518 (patch) | |
tree | 304c2176f7dc85a3c168fb936bc319f1d7914b90 /src | |
parent | f8853a8005e957345608086f839b7a7747d81586 (diff) | |
parent | e068345288f9a7fe8f4d3eb23fe0b91240132de1 (diff) | |
download | scala-411530a846e4b424080a43e3b696830932e36518.tar.gz scala-411530a846e4b424080a43e3b696830932e36518.tar.bz2 scala-411530a846e4b424080a43e3b696830932e36518.zip |
Merge pull request #4323 from axel22/t-concurrent-map-get-2.12.x
Fix SI-9147 Override `getOrElseUpdate` in `concurrent.Map`.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/concurrent/Map.scala | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/library/scala/collection/concurrent/Map.scala b/src/library/scala/collection/concurrent/Map.scala index 2eea15b8dc..f0a5f57225 100644 --- a/src/library/scala/collection/concurrent/Map.scala +++ b/src/library/scala/collection/concurrent/Map.scala @@ -86,4 +86,15 @@ trait Map[A, B] extends scala.collection.mutable.Map[A, B] { * @return `Some(v)` if the given key was previously mapped to some value `v`, or `None` otherwise */ def replace(k: A, v: B): Option[B] + + override def getOrElseUpdate(key: A, op: =>B): B = get(key) match { + case Some(v) => v + case None => + val v = op + putIfAbsent(key, v) match { + case Some(nv) => nv + case None => v + } + } + } |