Skip to content

Commit

Permalink
Use sum in count for constant folding of type based predicates (#…
Browse files Browse the repository at this point in the history
…48454)

* Use `sum` in `count` for constant folding for type based predicates.

* Use existing `_bool` functionality for type assertion

---------

Co-authored-by: Sukera <[email protected]>
  • Loading branch information
Seelengrab and Seelengrab authored Feb 4, 2023
1 parent d02516e commit c4fd8a4
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1354,15 +1354,7 @@ count(itr; init=0) = count(identity, itr; init)

count(f, itr; init=0) = _simple_count(f, itr, init)

_simple_count(pred, itr, init) = _simple_count_helper(Generator(pred, itr), init)

function _simple_count_helper(g, init::T) where {T}
n::T = init
for x in g
n += x::Bool
end
return n
end
_simple_count(pred, itr, init) = sum(_bool(pred), itr; init)

function _simple_count(::typeof(identity), x::Array{Bool}, init::T=0) where {T}
n::T = init
Expand Down

0 comments on commit c4fd8a4

Please sign in to comment.