Skip to content

Commit a7404f1

Browse files
authored
Merge pull request scala#7020 from szeiger/issue/10990
Add deprecated `updated` method to s.c.m.Map
2 parents e64564b + 36baab8 commit a7404f1

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/library/scala/collection/mutable/AnyRefMap.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,9 @@ class AnyRefMap[K <: AnyRef, V] private[collection] (defaultEntry: K => V, initi
381381

382382
override def ++[V2 >: V](xs: scala.collection.Iterable[(K, V2)]): AnyRefMap[K, V2] = concat(xs)
383383

384-
@deprecated("Use AnyRefMap.from(m).add(k,v) instead of m.updated(k, v)", "2.13.0")
385-
def updated[V1 >: V](key: K, value: V1): AnyRefMap[K, V1] = {
386-
val arm = clone().asInstanceOf[AnyRefMap[K, V1]]
387-
arm += ((key, value))
388-
arm
389-
}
384+
@deprecated("Use m.clone().addOne(k,v) instead of m.updated(k, v)", "2.13.0")
385+
override def updated[V1 >: V](key: K, value: V1): AnyRefMap[K, V1] =
386+
clone().asInstanceOf[AnyRefMap[K, V1]].addOne(key, value)
390387

391388
private[this] def foreachElement[A,B](elems: Array[AnyRef], f: A => B): Unit = {
392389
var i,j = 0

src/library/scala/collection/mutable/LongMap.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,12 +452,9 @@ final class LongMap[V] private[collection] (defaultEntry: Long => V, initialBuff
452452

453453
override def ++ [V1 >: V](xs: scala.collection.Iterable[(Long, V1)]): LongMap[V1] = concat(xs)
454454

455-
@deprecated("Use LongMap.from(m).add(k,v) instead of m.updated(k, v)", "2.13.0")
456-
def updated[V1 >: V](key: Long, value: V1): LongMap[V1] = {
457-
val lm = clone().asInstanceOf[LongMap[V1]]
458-
lm += (key, value)
459-
lm
460-
}
455+
@deprecated("Use m.clone().addOne(k,v) instead of m.updated(k, v)", "2.13.0")
456+
override def updated[V1 >: V](key: Long, value: V1): LongMap[V1] =
457+
clone().asInstanceOf[LongMap[V1]].addOne(key, value)
461458

462459
/** Applies a function to all keys of this map. */
463460
def foreachKey[A](f: Long => A): Unit = {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ trait MapOps[K, V, +CC[X, Y] <: MapOps[X, Y, CC, _], +C <: MapOps[K, V, CC, C]]
159159
this
160160
}
161161

162+
@deprecated("Use m.clone().addOne((k,v)) instead of m.updated(k, v)", "2.13.0")
163+
def updated[V1 >: V](key: K, value: V1): CC[K, V1] =
164+
clone().asInstanceOf[CC[K, V1]].addOne((key, value))
162165
}
163166

164167
/**

src/library/scala/collection/mutable/SortedMap.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ trait SortedMapOps[K, V, +CC[X, Y] <: Map[X, Y] with SortedMapOps[X, Y, CC, _],
4444
with MapOps[K, V, Map, C] {
4545

4646
def unsorted: Map[K, V]
47+
48+
@deprecated("Use m.clone().addOne((k,v)) instead of m.updated(k, v)", "2.13.0")
49+
override def updated[V1 >: V](key: K, value: V1): CC[K, V1] =
50+
clone().asInstanceOf[CC[K, V1]].addOne((key, value))
4751
}
4852

4953
@SerialVersionUID(3L)

0 commit comments

Comments
 (0)