Skip to content

Commit

Permalink
Merge pull request #16816 from JuliaLang/jb/fix16809
Browse files Browse the repository at this point in the history
fix #16809, perf regression in `in`
  • Loading branch information
JeffBezanson committed Jun 7, 2016
2 parents 58557b0 + e20b029 commit 0d1b4b6
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,29 +181,20 @@ end

const ShortCircuiting = Union{typeof(&), typeof(|)}

shortcircuits(::typeof(&), x::Bool) = !x
shortcircuits(::typeof(|), x::Bool) = x

shorted(::typeof(&)) = false
shorted(::typeof(|)) = true

sc_finish(::typeof(&)) = true
sc_finish(::typeof(|)) = false

## short-circuiting (sc) mapreduce definitions

function mapreduce_sc_impl(f, op, itr::AbstractArray)
function mapreduce_sc_impl(f, op::typeof(&), itr)
for x in itr
shortcircuits(op, f(x)) && return shorted(op)
f(x) || return false
end
return sc_finish(op)
return true
end

function mapreduce_sc_impl(f, op, itr)
function mapreduce_sc_impl(f, op::typeof(|), itr)
for x in itr
shortcircuits(op, f(x)) && return shorted(op)
f(x) && return true
end
return sc_finish(op)
return false
end

# mapreduce_sc tests if short-circuiting is safe;
Expand Down

0 comments on commit 0d1b4b6

Please sign in to comment.