From 8796db4291e5cf8a5461690ae865ed649a6060a3 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 8 Nov 2024 10:35:44 +0530 Subject: [PATCH] Update comment --- base/reduce.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/base/reduce.jl b/base/reduce.jl index fa41d55e4e0f2..6ceb76089d59c 100644 --- a/base/reduce.jl +++ b/base/reduce.jl @@ -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