Skip to content

Commit bc565e1

Browse files
committed
Prepare Array for deprecating generalized linear indexing
1 parent e9477be commit bc565e1

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

base/array.jl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,10 @@ done(a::Array,i) = (@_inline_meta; i == length(a)+1)
447447

448448
## Indexing: getindex ##
449449

450-
# This is more complicated than it needs to be in order to get Win64 through bootstrap
451450
getindex(A::Array, i1::Int) = arrayref(A, i1)
452-
getindex(A::Array, i1::Int, i2::Int, I::Int...) = (@_inline_meta; arrayref(A, i1, i2, I...)) # TODO: REMOVE FOR #14770
451+
getindex{T}(A::Array{T,1}, i1::Int) = arrayref(A, i1)
452+
getindex{T,N}(A::Array{T,N}, I::Vararg{Int,N}) = (@_inline_meta; arrayref(A, I...))
453+
getindex{T}(A::Array{T,0}) = (@_inline_meta; arrayref(A, 1))
453454

454455
# Faster contiguous indexing using copy! for UnitRange and Colon
455456
function getindex(A::Array, I::UnitRange{Int})
@@ -477,8 +478,15 @@ function getindex{S}(A::Array{S}, I::Range{Int})
477478
end
478479

479480
## Indexing: setindex! ##
480-
setindex!{T}(A::Array{T}, x, i1::Int) = arrayset(A, convert(T,x)::T, i1)
481-
setindex!{T}(A::Array{T}, x, i1::Int, i2::Int, I::Int...) = (@_inline_meta; arrayset(A, convert(T,x)::T, i1, i2, I...)) # TODO: REMOVE FOR #14770
481+
setindex!{T}(A::Array{T}, x, i::Int) = arrayset(A, convert(T,x)::T, i)
482+
setindex!{T}(A::Array{T,1}, x, i::Int) = arrayset(A, convert(T,x)::T, i)
483+
setindex!{T,N}(A::Array{T,N}, x, I::Vararg{Int,N}) = (@_inline_meta; arrayset(A, convert(T,x)::T, I...))
484+
setindex!{T}(A::Array{T,0}, x) = (@_inline_meta; arrayset(A, convert(T,x)::T, 1))
485+
486+
# These are needed for ambiguity with a method in essentials.jl for bootstrap
487+
setindex!(A::Array{Any,1}, x::ANY, i::Int) = arrayset(A, x, i)
488+
setindex!(A::Array{Any,0}, x::ANY) = arrayset(A, x, 1)
489+
setindex!{N}(A::Array{Any,N}, x::ANY, I::Vararg{Int,N}) = arrayset(A, x, I...)
482490

483491
# These are redundant with the abstract fallbacks but needed for bootstrap
484492
function setindex!(A::Array, x, I::AbstractVector{Int})
@@ -525,7 +533,8 @@ function setindex!{T}(A::Array{T}, X::Array{T}, c::Colon)
525533
end
526534

527535
setindex!(A::Array, x::Number, ::Colon) = fill!(A, x)
528-
setindex!{T, N}(A::Array{T, N}, x::Number, ::Vararg{Colon, N}) = fill!(A, x)
536+
# This causes a ton of ambiguities
537+
# setindex!{T, N}(A::Array{T, N}, x::Number, ::Vararg{Colon, N}) = fill!(A, x)
529538

530539
# efficiently grow an array
531540

base/multidimensional.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ using .IteratorsMD
180180
A[to_indices(A, (i1, I...))...]
181181
@propagate_inbounds setindex!(A::Array, v, i1::Union{Integer, CartesianIndex}, I::Union{Integer, CartesianIndex}...) =
182182
(A[to_indices(A, (i1, I...))...] = v; A)
183+
# But they may not expand to 1 or N indices; ensure the above doesn't shadow the general indexing fallbacks
184+
@propagate_inbounds getindex{T}(A::Array{T}, i1::Int, I::Int...) =
185+
_getindex(LinearFast(), A, i1, I...)
186+
@propagate_inbounds setindex!{T}(A::Array{T}, v, i1::Int, I::Int...) =
187+
_setindex!(LinearFast(), A, v, i1, I...)
183188

184189
# Support indexing with an array of CartesianIndex{N}s
185190
# Here we try to consume N of the indices (if there are that many available)

0 commit comments

Comments
 (0)