Skip to content

Commit c4fd8a4

Browse files
authored
Use sum in count for constant folding of type based predicates (#48454)
* Use `sum` in `count` for constant folding for type based predicates. * Use existing `_bool` functionality for type assertion --------- Co-authored-by: Sukera <Seelengrab@users.noreply.github.com>
1 parent d02516e commit c4fd8a4

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

base/reduce.jl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,15 +1354,7 @@ count(itr; init=0) = count(identity, itr; init)
13541354

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

1357-
_simple_count(pred, itr, init) = _simple_count_helper(Generator(pred, itr), init)
1358-
1359-
function _simple_count_helper(g, init::T) where {T}
1360-
n::T = init
1361-
for x in g
1362-
n += x::Bool
1363-
end
1364-
return n
1365-
end
1357+
_simple_count(pred, itr, init) = sum(_bool(pred), itr; init)
13661358

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

0 commit comments

Comments
 (0)