diff --git a/base/array.jl b/base/array.jl index 9fd36c5dfd715..2a776ae1e9df7 100644 --- a/base/array.jl +++ b/base/array.jl @@ -1273,12 +1273,16 @@ Stacktrace: deleteat!(a::Vector, inds) = _deleteat!(a, inds) deleteat!(a::Vector, inds::AbstractVector) = _deleteat!(a, to_indices(a, (inds,))[1]) -function _deleteat!(a::Vector, inds) +struct Nowhere; end +push!(::Nowhere, _) = nothing + +function _deleteat!(a::Vector, inds, dltd=Nowhere()) n = length(a) y = iterate(inds) y === nothing && return a n == 0 && throw(BoundsError(a, inds)) (p, s) = y + p <= n && push!(dltd, @inbounds a[p]) q = p+1 while true y = iterate(inds, s) @@ -1295,6 +1299,7 @@ function _deleteat!(a::Vector, inds) @inbounds a[p] = a[q] p += 1; q += 1 end + push!(dltd, @inbounds a[i]) q = i+1 end while q <= n @@ -1444,6 +1449,8 @@ function splice!(a::Vector, r::UnitRange{<:Integer}, ins=_default_splice) return v end +splice!(a::Vector, inds) = (dltds = eltype(a)[]; _deleteat!(a, inds, dltds); dltds) + function empty!(a::Vector) _deleteend!(a, length(a)) return a diff --git a/test/arrayops.jl b/test/arrayops.jl index 4f55a34c51fad..aa04aa0dfbac1 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -1342,6 +1342,7 @@ end @test a == [acopy[1:(first(idx)-1)]; repl; acopy[(last(idx)+1):end]] end end + @test splice!([4,3,2,1], [2, 4]) == [3, 1] end @testset "filter!" begin