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