@@ -848,7 +848,7 @@ private[collection] object RedBlackTree {
848
848
}
849
849
850
850
private [this ] def _union [A , B ](t1 : Tree [A , B ], t2 : Tree [A , B ])(implicit ordering : Ordering [A ]): Tree [A , B ] =
851
- if (t1 eq null ) t2
851
+ if (( t1 eq null ) || (t1 eq t2) ) t2
852
852
else if (t2 eq null ) t1
853
853
else {
854
854
val (l1, _, r1) = split(t1, t2.key)
@@ -859,6 +859,7 @@ private[collection] object RedBlackTree {
859
859
860
860
private [this ] def _intersect [A , B ](t1 : Tree [A , B ], t2 : Tree [A , B ])(implicit ordering : Ordering [A ]): Tree [A , B ] =
861
861
if ((t1 eq null ) || (t2 eq null )) null
862
+ else if (t1 eq t2) t1
862
863
else {
863
864
val (l1, b, r1) = split(t1, t2.key)
864
865
val tl = _intersect(l1, t2.left)
@@ -869,6 +870,7 @@ private[collection] object RedBlackTree {
869
870
870
871
private [this ] def _difference [A , B ](t1 : Tree [A , B ], t2 : Tree [A , B ])(implicit ordering : Ordering [A ]): Tree [A , B ] =
871
872
if ((t1 eq null ) || (t2 eq null )) t1
873
+ else if (t1 eq t2) null
872
874
else {
873
875
val (l1, _, r1) = split(t1, t2.key)
874
876
val tl = _difference(l1, t2.left)
0 commit comments