Skip to content

Commit 5451c7d

Browse files
authored
avoid vector allocation when PartitionIterator is cut short (#41950)
1 parent cdd2f30 commit 5451c7d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

base/iterators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,11 +1191,11 @@ end
11911191
struct IterationCutShort; end
11921192

11931193
function iterate(itr::PartitionIterator, state...)
1194-
v = Vector{eltype(itr.c)}(undef, itr.n)
11951194
# This is necessary to remember whether we cut the
11961195
# last element short. In such cases, we do return that
11971196
# element, but not the next one
11981197
state === (IterationCutShort(),) && return nothing
1198+
v = Vector{eltype(itr.c)}(undef, itr.n)
11991199
i = 0
12001200
y = iterate(itr.c, state...)
12011201
while y !== nothing

0 commit comments

Comments
 (0)