Skip to content

Commit

Permalink
Update comment
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Nov 9, 2024
1 parent 97f7161 commit 8796db4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ function foldl_impl(op::OP, nt, itr) where {OP}
end

function _foldl_impl(op::OP, init, itr) where {OP}
# Unroll the while loop once; if init is known, the call to op may
# be evaluated at compile time
# Unroll the loop once to check if the iterator is empty.
# If init is known, the call to op may be evaluated at compile time
y = iterate(itr)
y === nothing && return init
v = op(init, y[1])
# Using a for loop is more performant than a while loop (see #56492)
# This unrolls the loop a second time before entering the body
for x in Iterators.rest(itr, y[2])
v = op(v, x)
end
Expand Down

0 comments on commit 8796db4

Please sign in to comment.