Skip to content

Commit 14e1ba0

Browse files
authored
permit AbstractUnitRange for setindex!,deleteat!,splice! (#41809)
1 parent 1976045 commit 14e1ba0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

base/array.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ function getindex end
895895
@eval getindex(A::Array, i1::Int) = arrayref($(Expr(:boundscheck)), A, i1)
896896
@eval getindex(A::Array, i1::Int, i2::Int, I::Int...) = (@_inline_meta; arrayref($(Expr(:boundscheck)), A, i1, i2, I...))
897897

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

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

1458-
function deleteat!(a::Vector, r::UnitRange{<:Integer})
1458+
function deleteat!(a::Vector, r::AbstractUnitRange{<:Integer})
14591459
n = length(a)
14601460
isempty(r) || _deleteat!(a, first(r), length(r))
14611461
return a
@@ -1621,14 +1621,17 @@ Remove items at specified indices, and return a collection containing
16211621
the removed items.
16221622
Subsequent items are shifted left to fill the resulting gaps.
16231623
If specified, replacement values from an ordered collection will be spliced in
1624-
place of the removed items; in this case, `indices` must be a `UnitRange`.
1624+
place of the removed items; in this case, `indices` must be a `AbstractUnitRange`.
16251625
16261626
To insert `replacement` before an index `n` without removing any items, use
16271627
`splice!(collection, n:n-1, replacement)`.
16281628
16291629
!!! compat "Julia 1.5"
16301630
Prior to Julia 1.5, `indices` must always be a `UnitRange`.
16311631
1632+
!!! compat "Julia 1.8"
1633+
Prior to Julia 1.8, `indices` must be a `UnitRange` if splicing in replacement values.
1634+
16321635
# Examples
16331636
```jldoctest
16341637
julia> A = [-1, -2, -3, 5, 4, 3, -1]; splice!(A, 4:3, 2)
@@ -1646,7 +1649,7 @@ julia> A
16461649
-1
16471650
```
16481651
"""
1649-
function splice!(a::Vector, r::UnitRange{<:Integer}, ins=_default_splice)
1652+
function splice!(a::Vector, r::AbstractUnitRange{<:Integer}, ins=_default_splice)
16501653
v = a[r]
16511654
m = length(ins)
16521655
if m == 0

0 commit comments

Comments
 (0)