Skip to content

Commit

Permalink
Merge pull request #15660 from JuliaLang/ob/enumrange
Browse files Browse the repository at this point in the history
Avoid making a 10G array for no reason
  • Loading branch information
vtjnash committed Apr 1, 2016
2 parents 96ab46a + 28bd077 commit 3c9bf14
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions base/Enums.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ Base.read{T<:Enum}(io::IO, ::Type{T}) = T(read(io, Int32))
# generate code to test whether expr is in the given set of values
function membershiptest(expr, values)
lo, hi = extrema(values)
sv = sort(values)
if sv == [lo:hi;]
if length(values) == hi - lo + 1
:($lo <= $expr <= $hi)
elseif length(values) < 20
foldl((x1,x2)->:($x1 || ($expr == $x2)), :($expr == $(values[1])), values[2:end])
Expand Down

0 comments on commit 3c9bf14

Please sign in to comment.