Skip to content

Commit

Permalink
Reduce allocation in flatten (#29786)
Browse files Browse the repository at this point in the history
(cherry picked from commit 07ea302)
  • Loading branch information
mschauer authored and KristofferC committed Oct 31, 2018
1 parent 0c404ec commit 80c1a25
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,13 @@ length(f::Flatten{Tuple{}}) = 0
end
x = (state === () ? iterate(f.it) : iterate(f.it, state[1]))
x === nothing && return nothing
iterate(f, (x[2], x[1]))
y = iterate(x[1])
while y === nothing
x = iterate(f.it, x[2])
x === nothing && return nothing
y = iterate(x[1])
end
return y[1], (x[2], x[1], y[2])
end

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

0 comments on commit 80c1a25

Please sign in to comment.