Skip to content

Commit a6718a3

Browse files
authored
Merge pull request scala/scala#10590 from som-snytt/doc/getOrElseUpdate
Improve name of default value
2 parents 93602dd + d2b6e8c commit a6718a3

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

library/src/scala/collection/concurrent/Map.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import scala.annotation.tailrec
3232
* provides all of the methods a `Map` does, with the difference that all the
3333
* changes are atomic. It also describes methods specific to concurrent maps.
3434
*
35-
* '''Note''': The concurrent maps do not accept `'''null'''` for keys or values.
36-
*
3735
* @define atomicop
3836
* This is an atomic operation.
3937
*/
@@ -92,10 +90,10 @@ trait Map[K, V] extends scala.collection.mutable.Map[K, V] {
9290
*/
9391
def replace(k: K, v: V): Option[V]
9492

95-
override def getOrElseUpdate(key: K, op: => V): V = get(key) match {
93+
override def getOrElseUpdate(key: K, @deprecatedName("op", since="2.13.13") defaultValue: => V): V = get(key) match {
9694
case Some(v) => v
9795
case None =>
98-
val v = op
96+
val v = defaultValue
9997
putIfAbsent(key, v) match {
10098
case Some(ov) => ov
10199
case None => v

library/src/scala/collection/concurrent/TrieMap.scala

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -941,25 +941,25 @@ final class TrieMap[K, V] private (r: AnyRef, rtupd: AtomicReferenceFieldUpdater
941941
// TODO once computeIfAbsent is added to concurrent.Map,
942942
// move the comment there and tweak the 'at most once' part
943943
/** If the specified key is not already in the map, computes its value using
944-
* the given thunk `op` and enters it into the map.
945-
*
946-
* If the specified mapping function throws an exception,
947-
* that exception is rethrown.
948-
*
949-
* Note: This method will invoke op at most once.
950-
* However, `op` may be invoked without the result being added to the map if
951-
* a concurrent process is also trying to add a value corresponding to the
952-
* same key `k`.
953-
*
954-
* @param k the key to modify
955-
* @param op the expression that computes the value
956-
* @return the newly added value
957-
*/
958-
override def getOrElseUpdate(k: K, op: => V): V = {
944+
* the given thunk `defaultValue` and enters it into the map.
945+
*
946+
* If the specified mapping function throws an exception,
947+
* that exception is rethrown.
948+
*
949+
* Note: This method will invoke `defaultValue` at most once.
950+
* However, `defaultValue` may be invoked without the result being added to the map if
951+
* a concurrent process is also trying to add a value corresponding to the
952+
* same key `k`.
953+
*
954+
* @param k the key to modify
955+
* @param defaultValue the expression that computes the value
956+
* @return the newly added value
957+
*/
958+
override def getOrElseUpdate(k: K, @deprecatedName("op", since="2.13.13") defaultValue: => V): V = {
959959
val hc = computeHash(k)
960960
lookuphc(k, hc) match {
961961
case INodeBase.NO_SUCH_ELEMENT_SENTINEL =>
962-
val v = op
962+
val v = defaultValue
963963
insertifhc(k, hc, v, INode.KEY_ABSENT, fullEquals = false /* unused */) match {
964964
case Some(oldValue) => oldValue
965965
case None => v

library/src/scala/collection/mutable/Map.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ trait MapOps[K, V, +CC[X, Y] <: MapOps[X, Y, CC, _], +C <: MapOps[K, V, CC, C]]
135135
* multiple times, or may evaluate `op` without inserting the result.
136136
*
137137
* @param key the key to test
138-
* @param op the computation yielding the value to associate with `key`, if
138+
* @param defaultValue the computation yielding the value to associate with `key`, if
139139
* `key` is previously unbound.
140140
* @return the value associated with key (either previously or as a result
141141
* of executing the method).
142142
*/
143-
def getOrElseUpdate(key: K, op: => V): V =
143+
def getOrElseUpdate(key: K, @deprecatedName("op", since="2.13.13") defaultValue: => V): V =
144144
get(key) match {
145145
case Some(v) => v
146-
case None => val d = op; this(key) = d; d
146+
case None => val d = defaultValue; this(key) = d; d
147147
}
148148

149149
/** Removes a key from this map, returning the value associated previously

0 commit comments

Comments
 (0)