Skip to content

Commit

Permalink
issubset(l, r::AbstractSet): optimize early exit case
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Aug 8, 2019
1 parent 971d18b commit e4456d0
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions base/abstractset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,14 @@ issubset, ⊆, ⊇
function issubset(l, r)
if haslength(r)
rlen = length(r)
#This threshold was empirically determined by repeatedly
#sampling using these two methods (see #26198)
lenthresh = 70

if rlen > lenthresh && !isa(r, AbstractSet)
if isa(l, AbstractSet)
# check l for too many unique elements
length(l) > rlen && return false
end
# if r is big enough, convert it to a Set
# threshold empirically determined by repeatedly
# sampling using these two methods (see #26198)
if rlen > 70 && !isa(r, AbstractSet)
return issubset(l, Set(r))
end
end
Expand Down

0 comments on commit e4456d0

Please sign in to comment.