Skip to content

Commit 643f9b2

Browse files
committed
Merge pull request #14582 from zsunberg/master
RFC: fixes IntSet copy!(a,a) for a === a; #14581
2 parents 1d01e0a + 166f484 commit 643f9b2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

base/intset.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,12 @@ function symdiff!(s::IntSet, ns)
159159
end
160160

161161
function copy!(to::IntSet, from::IntSet)
162-
empty!(to)
163-
union!(to, from)
162+
if is(to, from)
163+
return to
164+
else
165+
empty!(to)
166+
return union!(to, from)
167+
end
164168
end
165169

166170
in(n, s::IntSet) = n < 0 ? false : (n > typemax(Int) ? s.fill1s : in(convert(Int, n), s))

test/intset.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ k = IntSet([4, 5])
8686
copy!(k, i)
8787
@test k == i
8888
@test !(k === i)
89+
copy!(k, k)
90+
@test k == i
8991

9092
# unions
9193
i = IntSet([1, 2, 3])

0 commit comments

Comments
 (0)