Skip to content

Commit

Permalink
permit AbstractUnitRange for setindex!,deleteat!,splice! (JuliaLang#4…
Browse files Browse the repository at this point in the history
  • Loading branch information
mkitti authored and LilithHafner committed Mar 8, 2022
1 parent 4e15294 commit 0e0395e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ function getindex end
@eval getindex(A::Array, i1::Int) = arrayref($(Expr(:boundscheck)), A, i1)
@eval getindex(A::Array, i1::Int, i2::Int, I::Int...) = (@_inline_meta; arrayref($(Expr(:boundscheck)), A, i1, i2, I...))

# Faster contiguous indexing using copyto! for UnitRange and Colon
# Faster contiguous indexing using copyto! for AbstractUnitRange and Colon
function getindex(A::Array, I::AbstractUnitRange{<:Integer})
@_inline_meta
@boundscheck checkbounds(A, I)
Expand Down Expand Up @@ -955,7 +955,7 @@ function setindex!(A::Array, X::AbstractArray, I::AbstractVector{Int})
end

# Faster contiguous setindex! with copyto!
function setindex!(A::Array{T}, X::Array{T}, I::UnitRange{Int}) where T
function setindex!(A::Array{T}, X::Array{T}, I::AbstractUnitRange{Int}) where T
@_inline_meta
@boundscheck checkbounds(A, I)
lI = length(I)
Expand Down Expand Up @@ -1455,7 +1455,7 @@ julia> deleteat!([6, 5, 4, 3, 2, 1], 2)
"""
deleteat!(a::Vector, i::Integer) = (_deleteat!(a, i, 1); a)

function deleteat!(a::Vector, r::UnitRange{<:Integer})
function deleteat!(a::Vector, r::AbstractUnitRange{<:Integer})
n = length(a)
isempty(r) || _deleteat!(a, first(r), length(r))
return a
Expand Down Expand Up @@ -1621,14 +1621,17 @@ Remove items at specified indices, and return a collection containing
the removed items.
Subsequent items are shifted left to fill the resulting gaps.
If specified, replacement values from an ordered collection will be spliced in
place of the removed items; in this case, `indices` must be a `UnitRange`.
place of the removed items; in this case, `indices` must be a `AbstractUnitRange`.
To insert `replacement` before an index `n` without removing any items, use
`splice!(collection, n:n-1, replacement)`.
!!! compat "Julia 1.5"
Prior to Julia 1.5, `indices` must always be a `UnitRange`.
!!! compat "Julia 1.8"
Prior to Julia 1.8, `indices` must be a `UnitRange` if splicing in replacement values.
# Examples
```jldoctest
julia> A = [-1, -2, -3, 5, 4, 3, -1]; splice!(A, 4:3, 2)
Expand All @@ -1646,7 +1649,7 @@ julia> A
-1
```
"""
function splice!(a::Vector, r::UnitRange{<:Integer}, ins=_default_splice)
function splice!(a::Vector, r::AbstractUnitRange{<:Integer}, ins=_default_splice)
v = a[r]
m = length(ins)
if m == 0
Expand Down

0 comments on commit 0e0395e

Please sign in to comment.