Skip to content

Commit

Permalink
specialize on type in getindex for types
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Aug 14, 2016
1 parent 75e88af commit c13fed6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,18 @@ similar{N}(a::Array, T::Type, dims::Dims{N}) = Array{T,N}(dims)
similar{T,N}(a::Array{T}, dims::Dims{N}) = Array{T,N}(dims)

# T[x...] constructs Array{T,1}
function getindex(T::Type, vals...)
function getindex{T}(::Type{T}, vals...)
a = Array{T,1}(length(vals))
@inbounds for i = 1:length(vals)
a[i] = vals[i]
end
return a
end

getindex(T::Type) = Array{T,1}(0)
getindex(T::Type, x) = (a = Array{T,1}(1); @inbounds a[1] = x; a)
getindex(T::Type, x, y) = (a = Array{T,1}(2); @inbounds (a[1] = x; a[2] = y); a)
getindex(T::Type, x, y, z) = (a = Array{T,1}(3); @inbounds (a[1] = x; a[2] = y; a[3] = z); a)
getindex{T}(::Type{T}) = (@_inline_meta; Array{T,1}(0))
getindex{T}(::Type{T}, x) = (@_inline_meta; a = Array{T,1}(1); @inbounds a[1] = x; a)
getindex{T}(::Type{T}, x, y) = (@_inline_meta; a = Array{T,1}(2); @inbounds (a[1] = x; a[2] = y); a)
getindex{T}(::Type{T}, x, y, z) = (@_inline_meta; a = Array{T,1}(3); @inbounds (a[1] = x; a[2] = y; a[3] = z); a)

function getindex(::Type{Any}, vals::ANY...)
a = Array{Any,1}(length(vals))
Expand Down

0 comments on commit c13fed6

Please sign in to comment.