Skip to content

Commit

Permalink
fix prepend StackOverflow issue
Browse files Browse the repository at this point in the history
Attempt to fix #54711
Test introduced by #36227
  • Loading branch information
vtjnash committed Jun 6, 2024
1 parent ec32170 commit fec1e18
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 @@ -1316,8 +1316,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; a)

function _append!(a::AbstractVector, ::Union{HasLength,HasShape}, iter)
n = Int(length(iter))::Int
Expand Down Expand Up @@ -1376,10 +1375,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 in iter; prepend!(a, v); end; a)

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

0 comments on commit fec1e18

Please sign in to comment.