Skip to content

Commit df7d352

Browse files
committed
Replace primitive Array{...}(dims...) constructors with Array{...}(junk, dims...).
1 parent 268f878 commit df7d352

File tree

2 files changed

+62
-23
lines changed

2 files changed

+62
-23
lines changed

base/boot.jl

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export
123123
SimpleVector, AbstractArray, DenseArray,
124124
# special objects
125125
Function, CodeInfo, Method, MethodTable, TypeMapEntry, TypeMapLevel,
126-
Module, Symbol, Task, Array, WeakRef, VecElement,
126+
Module, Symbol, Task, Array, junk, WeakRef, VecElement,
127127
# numeric types
128128
Number, Real, Integer, Bool, Ref, Ptr,
129129
AbstractFloat, Float16, Float32, Float64,
@@ -350,25 +350,44 @@ unsafe_convert(::Type{T}, x::T) where {T} = x
350350
const NTuple{N,T} = Tuple{Vararg{T,N}}
351351

352352

353-
# primitive array constructors
354-
Array{T,N}(d::NTuple{N,Int}) where {T,N} =
355-
ccall(:jl_new_array, Array{T,N}, (Any, Any), Array{T,N}, d)
356-
Array{T,1}(d::NTuple{1,Int}) where {T} = Array{T,1}(getfield(d,1))
357-
Array{T,2}(d::NTuple{2,Int}) where {T} = Array{T,2}(getfield(d,1), getfield(d,2))
358-
Array{T,3}(d::NTuple{3,Int}) where {T} = Array{T,3}(getfield(d,1), getfield(d,2), getfield(d,3))
359-
Array{T,N}(d::Vararg{Int,N}) where {T,N} = ccall(:jl_new_array, Array{T,N}, (Any, Any), Array{T,N}, d)
360-
Array{T,1}(m::Int) where {T} = ccall(:jl_alloc_array_1d, Array{T,1}, (Any, Int), Array{T,1}, m)
361-
Array{T,2}(m::Int, n::Int) where {T} =
353+
## primitive Array constructors
354+
function junk end
355+
# type and dimensionality specified, accepting dims as series of Ints
356+
Array{T,1}(::typeof(junk), m::Int) where {T} =
357+
ccall(:jl_alloc_array_1d, Array{T,1}, (Any, Int), Array{T,1}, m)
358+
Array{T,2}(::typeof(junk), m::Int, n::Int) where {T} =
362359
ccall(:jl_alloc_array_2d, Array{T,2}, (Any, Int, Int), Array{T,2}, m, n)
363-
Array{T,3}(m::Int, n::Int, o::Int) where {T} =
360+
Array{T,3}(::typeof(junk), m::Int, n::Int, o::Int) where {T} =
364361
ccall(:jl_alloc_array_3d, Array{T,3}, (Any, Int, Int, Int), Array{T,3}, m, n, o)
362+
Array{T,N}(::typeof(junk), d::Vararg{Int,N}) where {T,N} =
363+
ccall(:jl_new_array, Array{T,N}, (Any, Any), Array{T,N}, d)
364+
# type and dimensionality specified, accepting dims as tuples of Ints
365+
Array{T,1}(::typeof(junk), d::NTuple{1,Int}) where {T} = Array{T,1}(junk, getfield(d,1))
366+
Array{T,2}(::typeof(junk), d::NTuple{2,Int}) where {T} = Array{T,2}(junk, getfield(d,1), getfield(d,2))
367+
Array{T,3}(::typeof(junk), d::NTuple{3,Int}) where {T} = Array{T,3}(junk, getfield(d,1), getfield(d,2), getfield(d,3))
368+
Array{T,N}(::typeof(junk), d::NTuple{N,Int}) where {T,N} = ccall(:jl_new_array, Array{T,N}, (Any, Any), Array{T,N}, d)
369+
# type but not dimensionality specified
370+
Array{T}(::typeof(junk), m::Int) where {T} = Array{T,1}(junk, m)
371+
Array{T}(::typeof(junk), m::Int, n::Int) where {T} = Array{T,2}(junk, m, n)
372+
Array{T}(::typeof(junk), m::Int, n::Int, o::Int) where {T} = Array{T,3}(junk, m, n, o)
373+
Array{T}(::typeof(junk), d::NTuple{N,Int}) where {T,N} = Array{T,N}(junk, d)
374+
# empty vector constructor
375+
Array{T,1}() where {T} = Array{T,1}(junk, 0)
376+
377+
## preexisting Array constructors, i.e. without junk, to deprecate
378+
# type and dimensionality specified, accepting dims as series of Ints
379+
Array{T,1}(m::Int) where {T} = Array{T,1}(junk, m)
380+
Array{T,2}(m::Int, n::Int) where {T} = Array{T,2}(junk, m, n)
381+
Array{T,3}(m::Int, n::Int, o::Int) where {T} = Array{T,3}(junk, m, n, o)
382+
Array{T,N}(d::Vararg{Int,N}) where {T,N} = Array{T,N}(junk, d)
383+
# type and dimensionality specified, accepting dims as tuples of Ints
384+
Array{T,N}(d::NTuple{N,Int}) where {T,N} = Array{T,N}(junk, d)
385+
# type but not dimensionality specified
386+
Array{T}(m::Int) where {T} = Array{T}(junk, m)
387+
Array{T}(m::Int, n::Int) where {T} = Array{T}(junk, m, n)
388+
Array{T}(m::Int, n::Int, o::Int) where {T} = Array{T}(junk, m, n, o)
389+
Array{T}(d::NTuple{N,Int}) where {T,N} = Array{T}(junk, d)
365390

366-
Array{T}(d::NTuple{N,Int}) where {T,N} = Array{T,N}(d)
367-
Array{T}(m::Int) where {T} = Array{T,1}(m)
368-
Array{T}(m::Int, n::Int) where {T} = Array{T,2}(m, n)
369-
Array{T}(m::Int, n::Int, o::Int) where {T} = Array{T,3}(m, n, o)
370-
371-
Array{T,1}() where {T} = Array{T,1}(0)
372391

373392
# primitive Symbol constructors
374393
function Symbol(s::String)

base/sysimg.jl

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,37 @@ include("abstractarray.jl")
130130
include("subarray.jl")
131131
include("reinterpretarray.jl")
132132

133-
# Array convenience converting constructors
133+
134+
# ## dims-type-converting Array constructors for convenience
135+
# type and dimensionality specified, accepting dims as series of Integers
136+
Vector{T}(::typeof(junk), m::Integer) where {T} = Vector{T}(junk, Int(m))
137+
Matrix{T}(::typeof(junk), m::Integer, n::Integer) where {T} = Matrix{T}(junk, Int(m), Int(n))
138+
# type but not dimensionality specified, accepting dims as series of Integers
139+
Array{T}(::typeof(junk), m::Integer) where {T} = Array{T,1}(junk, Int(m))
140+
Array{T}(::typeof(junk), m::Integer, n::Integer) where {T} = Array{T,2}(junk, Int(m), Int(n))
141+
Array{T}(::typeof(junk), m::Integer, n::Integer, o::Integer) where {T} = Array{T,3}(junk, Int(m), Int(n), Int(o))
142+
Array{T}(::typeof(junk), d::Integer...) where {T} = Array{T}(junk, convert(Tuple{Vararg{Int}}, d))
143+
# dimensionality but not type specified, accepting dims as series of Integers
144+
Vector(::typeof(junk), m::Integer) = Vector{Any}(junk, Int(m))
145+
Matrix(::typeof(junk), m::Integer, n::Integer) = Matrix{Any}(junk, Int(m), Int(n))
146+
# empty vector constructor
147+
Vector() = Vector{Any}(junk, 0)
148+
149+
## preexisting dims-type-converting Array constructors for convenience, i.e. without junk, to deprecate
150+
# type and dimensionality specified, accepting dims as series of Integers
151+
Vector{T}(m::Integer) where {T} = Vector{T}(Int(m))
152+
Matrix{T}(m::Integer, n::Integer) where {T} = Matrix{T}(Int(m), Int(n))
153+
# type but not dimensionality specified, accepting dims as series of Integers
134154
Array{T}(m::Integer) where {T} = Array{T,1}(Int(m))
135155
Array{T}(m::Integer, n::Integer) where {T} = Array{T,2}(Int(m), Int(n))
136156
Array{T}(m::Integer, n::Integer, o::Integer) where {T} = Array{T,3}(Int(m), Int(n), Int(o))
137157
Array{T}(d::Integer...) where {T} = Array{T}(convert(Tuple{Vararg{Int}}, d))
138-
139-
Vector() = Array{Any,1}(0)
140-
Vector{T}(m::Integer) where {T} = Array{T,1}(Int(m))
141-
Vector(m::Integer) = Array{Any,1}(Int(m))
142-
Matrix{T}(m::Integer, n::Integer) where {T} = Matrix{T}(Int(m), Int(n))
158+
# dimensionality but not type specified, accepting dims as series of Integers
159+
Vector(m::Integer) = Vector{Any}(Int(m))
143160
Matrix(m::Integer, n::Integer) = Matrix{Any}(Int(m), Int(n))
161+
# empty vector constructor
162+
Vector() = Vector{Any}(0)
163+
144164

145165
# numeric operations
146166
include("hashing.jl")

0 commit comments

Comments
 (0)