Skip to content

Commit

Permalink
avoid vector allocation when PartitionIterator is cut short (JuliaLan…
Browse files Browse the repository at this point in the history
  • Loading branch information
felipenoris authored and LilithHafner committed Mar 8, 2022
1 parent 2bea4df commit 726af79
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1191,11 +1191,11 @@ end
struct IterationCutShort; end

function iterate(itr::PartitionIterator, state...)
v = Vector{eltype(itr.c)}(undef, itr.n)
# This is necessary to remember whether we cut the
# last element short. In such cases, we do return that
# element, but not the next one
state === (IterationCutShort(),) && return nothing
v = Vector{eltype(itr.c)}(undef, itr.n)
i = 0
y = iterate(itr.c, state...)
while y !== nothing
Expand Down

0 comments on commit 726af79

Please sign in to comment.