Skip to content

Commit

Permalink
avoid vector allocation when PartitionIterator is cut short (#41950)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipenoris authored Aug 24, 2021
1 parent cdd2f30 commit 5451c7d
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 5451c7d

Please sign in to comment.