Skip to content

Commit

Permalink
fix prepend StackOverflow issue (#54718)
Browse files Browse the repository at this point in the history
Attempt to fix #54711
Test introduced by #36227

---------

Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
(cherry picked from commit 9477472)
  • Loading branch information
vtjnash authored and KristofferC committed Jun 13, 2024
1 parent 4d53a38 commit fe51261
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1312,8 +1312,7 @@ end

append!(a::AbstractVector, iter) = _append!(a, IteratorSize(iter), iter)
push!(a::AbstractVector, iter...) = append!(a, iter)

append!(a::AbstractVector, iter...) = foldl(append!, iter, init=a)
append!(a::AbstractVector, iter...) = (for v in iter; append!(a, v); end; return a)

function _append!(a::AbstractVector, ::Union{HasLength,HasShape}, iter)
n = Int(length(iter))::Int
Expand Down Expand Up @@ -1372,10 +1371,9 @@ function prepend!(a::Vector{T}, items::Union{AbstractVector{<:T},Tuple}) where T
return a
end

prepend!(a::Vector, iter) = _prepend!(a, IteratorSize(iter), iter)
pushfirst!(a::Vector, iter...) = prepend!(a, iter)

prepend!(a::AbstractVector, iter...) = foldr((v, a) -> prepend!(a, v), iter, init=a)
prepend!(a::AbstractVector, iter) = _prepend!(a, IteratorSize(iter), iter)
pushfirst!(a::AbstractVector, iter...) = prepend!(a, iter)
prepend!(a::AbstractVector, iter...) = (for v = reverse(iter); prepend!(a, v); end; return a)

function _prepend!(a::Vector, ::Union{HasLength,HasShape}, iter)
@_terminates_locally_meta
Expand Down

0 comments on commit fe51261

Please sign in to comment.