Skip to content

Commit 1536425

Browse files
mschauerKristofferC
authored andcommitted
Reduce allocation in flatten (#29786)
(cherry picked from commit 07ea302)
1 parent bfe3882 commit 1536425

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

base/iterators.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,13 @@ length(f::Flatten{Tuple{}}) = 0
906906
end
907907
x = (state === () ? iterate(f.it) : iterate(f.it, state[1]))
908908
x === nothing && return nothing
909-
iterate(f, (x[2], x[1]))
909+
y = iterate(x[1])
910+
while y === nothing
911+
x = iterate(f.it, x[2])
912+
x === nothing && return nothing
913+
y = iterate(x[1])
914+
end
915+
return y[1], (x[2], x[1], y[2])
910916
end
911917

912918
reverse(f::Flatten) = Flatten(reverse(itr) for itr in reverse(f.it))

0 commit comments

Comments
 (0)