Skip to content

Commit 437085e

Browse files
committed
fix mutableWithKV to actually use the new value
minor opt to some mutable methods - when converting from immutable to a new mutable Tree, the counts should be initial values (making the tree mutable), not the current counts (making it immutable)
1 parent 4c02ca2 commit 437085e

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

library/src/scala/collection/immutable/RedBlackTree.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,14 +584,14 @@ private[collection] object NewRedBlackTree {
584584
else if (mutable) {
585585
_key = newKey
586586
this
587-
} else new Tree(newKey, _value.asInstanceOf[AnyRef], _left, _right, _count)
587+
} else new Tree(newKey, _value.asInstanceOf[AnyRef], _left, _right, initialCount)
588588
}
589589
def mutableWithV[B1 >: B](newValue: B1): Tree[A, B1] = {
590590
if (newValue.asInstanceOf[AnyRef] eq _value.asInstanceOf[AnyRef]) this
591591
else if (mutable) {
592592
_value = newValue.asInstanceOf[AnyRef]
593593
this
594-
} else new Tree(_key, newValue.asInstanceOf[AnyRef], _left, _right, _count)
594+
} else new Tree(_key, newValue.asInstanceOf[AnyRef], _left, _right, initialCount)
595595
}
596596
//Note - in 2.13 remove his method
597597
//due to the handling of keys in 2.13 we never replace a key
@@ -600,9 +600,9 @@ private[collection] object NewRedBlackTree {
600600
(newValue.asInstanceOf[AnyRef] eq _value.asInstanceOf[AnyRef])) this
601601
else if (mutable) {
602602
_key = newKey
603-
_value = value.asInstanceOf[AnyRef]
603+
_value = newValue.asInstanceOf[AnyRef]
604604
this
605-
} else new Tree(newKey, newValue.asInstanceOf[AnyRef], _left, _right, _count)
605+
} else new Tree(newKey, newValue.asInstanceOf[AnyRef], _left, _right, initialCount)
606606
}
607607
def mutableWithLeft[B1 >: B](newLeft: Tree[A, B1]): Tree[A, B1] = {
608608
if (_left eq newLeft) this

library/src/scala/collection/immutable/TreeMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ final class TreeMap[A, +B] private (tree: RB.Tree[A, B])(implicit val ordering:
287287
private var currentMutableTree: RB.Tree[A,B1] = tree0
288288
def finalTree = beforePublish(currentMutableTree)
289289
override def apply(kv: (A, B1)): Unit = {
290-
currentMutableTree= mutableUpd(currentMutableTree, kv._1, kv._2)
290+
currentMutableTree = mutableUpd(currentMutableTree, kv._1, kv._2)
291291
}
292292
@tailrec def addAll(ls: LinearSeq[(A, B1)]): Unit = {
293293
if (!ls.isEmpty) {

0 commit comments

Comments
 (0)