Skip to content

Commit

Permalink
issubset: check IteratorSize trait before calling length (#28871)
Browse files Browse the repository at this point in the history
(cherry picked from commit 24de931)
  • Loading branch information
timholy authored and KristofferC committed Aug 26, 2018
1 parent 591b9d5 commit fc5325e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
17 changes: 9 additions & 8 deletions base/abstractset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,15 @@ end
<=(l::AbstractSet, r::AbstractSet) = l r

function issubset(l, r)

rlen = length(r)
#This threshold was empirically determined by repeatedly
#sampling using these two methods.
lenthresh = 70

if rlen > lenthresh && !isa(r, AbstractSet)
return issubset(l, Set(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)
return issubset(l, Set(r))
end
end

for elt in l
Expand Down
13 changes: 13 additions & 0 deletions test/sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -604,3 +604,16 @@ end
end
end
end

struct OpenInterval{T}
lower::T
upper::T
end
Base.in(x, i::OpenInterval) = i.lower < x < i.upper
Base.IteratorSize(::Type{<:OpenInterval}) = Base.SizeUnknown()

@testset "Continuous sets" begin
i = OpenInterval(2, 4)
@test 3 i
@test issubset(3, i)
end

0 comments on commit fc5325e

Please sign in to comment.