Skip to content

Commit

Permalink
Merge pull request #17025 from JuliaLang/rf/type-getindex-123
Browse files Browse the repository at this point in the history
implement separately getindex(::Type, x [,y [,z]]) for efficiency
  • Loading branch information
timholy authored Jun 20, 2016
2 parents 4e6740d + 6465999 commit 1419be0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ function getindex(T::Type, vals...)
end
return a
end

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

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

0 comments on commit 1419be0

Please sign in to comment.