Skip to content

Commit 3c1e9d0

Browse files
Sacha0fredrikekre
authored andcommitted
Replace Array{...}(shape...)-like calls in base/[b-d]* (less base/docs/basedocs.jl and base/distributed/*). (#24756)
1 parent e64ad77 commit 3c1e9d0

File tree

8 files changed

+39
-39
lines changed

8 files changed

+39
-39
lines changed

base/bitarray.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mutable struct BitArray{N} <: DenseArray{Bool, N}
2222
i += 1
2323
end
2424
nc = num_bit_chunks(n)
25-
chunks = Vector{UInt64}(nc)
25+
chunks = Vector{UInt64}(uninitialized, nc)
2626
nc > 0 && (chunks[end] = UInt64(0))
2727
b = new(chunks, n)
2828
N != 1 && (b.dims = dims)
@@ -348,7 +348,7 @@ similar(B::BitArray, dims::Dims) = BitArray(dims...)
348348
similar(B::BitArray, T::Type{Bool}, dims::Dims) = BitArray(dims)
349349
# changing type to a non-Bool returns an Array
350350
# (this triggers conversions like float(bitvector) etc.)
351-
similar(B::BitArray, T::Type, dims::Dims) = Array{T}(dims)
351+
similar(B::BitArray, T::Type, dims::Dims) = Array{T}(uninitialized, dims)
352352

353353
function fill!(B::BitArray, x)
354354
y = convert(Bool, x)
@@ -502,7 +502,7 @@ end
502502
convert(::Type{Array{T}}, B::BitArray{N}) where {T,N} = convert(Array{T,N}, B)
503503
convert(::Type{Array{T,N}}, B::BitArray{N}) where {T,N} = _convert(Array{T,N}, B) # see #15801
504504
function _convert(::Type{Array{T,N}}, B::BitArray{N}) where {T,N}
505-
A = Array{T}(size(B))
505+
A = Array{T}(uninitialized, size(B))
506506
Bc = B.chunks
507507
@inbounds for i = 1:length(A)
508508
A[i] = unsafe_bitgetindex(Bc, i)
@@ -620,7 +620,7 @@ gen_bitarray(::IsInfinite, itr) = throw(ArgumentError("infinite-size iterable u
620620

621621
function gen_bitarray_from_itr(itr, st)
622622
B = empty!(BitArray(bitcache_size))
623-
C = Vector{Bool}(bitcache_size)
623+
C = Vector{Bool}(uninitialized, bitcache_size)
624624
Bc = B.chunks
625625
ind = 1
626626
cind = 1
@@ -645,7 +645,7 @@ end
645645

646646
function fill_bitarray_from_itr!(B::BitArray, itr, st)
647647
n = length(B)
648-
C = Vector{Bool}(bitcache_size)
648+
C = Vector{Bool}(uninitialized, bitcache_size)
649649
Bc = B.chunks
650650
ind = 1
651651
cind = 1
@@ -1189,7 +1189,7 @@ end
11891189

11901190
for f in (:+, :-)
11911191
@eval function ($f)(A::BitArray, B::BitArray)
1192-
r = Array{Int}(promote_shape(size(A), size(B)))
1192+
r = Array{Int}(uninitialized, promote_shape(size(A), size(B)))
11931193
ai = start(A)
11941194
bi = start(B)
11951195
ri = 1
@@ -1649,7 +1649,7 @@ end
16491649
function find(B::BitArray)
16501650
l = length(B)
16511651
nnzB = count(B)
1652-
I = Vector{Int}(nnzB)
1652+
I = Vector{Int}(uninitialized, nnzB)
16531653
nnzB == 0 && return I
16541654
Bc = B.chunks
16551655
Bcount = 1
@@ -1683,8 +1683,8 @@ findn(B::BitVector) = find(B)
16831683

16841684
function findn(B::BitMatrix)
16851685
nnzB = count(B)
1686-
I = Vector{Int}(nnzB)
1687-
J = Vector{Int}(nnzB)
1686+
I = Vector{Int}(uninitialized, nnzB)
1687+
J = Vector{Int}(uninitialized, nnzB)
16881688
cnt = 1
16891689
for j = 1:size(B,2), i = 1:size(B,1)
16901690
if B[i,j]

base/broadcast.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ end
168168
@nexprs $N i->(A_{i+1} = Bs[i])
169169
@nexprs $nargs i->(keep_i = keeps[i])
170170
@nexprs $nargs i->(Idefault_i = Idefaults[i])
171-
C = Vector{Bool}(bitcache_size)
171+
C = Vector{Bool}(uninitialized, bitcache_size)
172172
Bc = B.chunks
173173
ind = 1
174174
cind = 1

base/channels.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ mutable struct Channel{T} <: AbstractChannel
4242
if sz < 0
4343
throw(ArgumentError("Channel size must be either 0, a positive integer or Inf"))
4444
end
45-
ch = new(Condition(), Condition(), :open, Nullable{Exception}(), Vector{T}(0), sz, 0)
45+
ch = new(Condition(), Condition(), :open, Nullable{Exception}(), Vector{T}(), sz, 0)
4646
if sz == 0
47-
ch.takers = Vector{Task}(0)
48-
ch.putters = Vector{Task}(0)
47+
ch.takers = Vector{Task}()
48+
ch.putters = Vector{Task}()
4949
end
5050
return ch
5151
end

base/combinatorics.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
# Factorials
44

5-
const _fact_table64 = Vector{Int64}(20)
5+
const _fact_table64 = Vector{Int64}(uninitialized, 20)
66
_fact_table64[1] = 1
77
for n in 2:20
88
_fact_table64[n] = _fact_table64[n-1] * n
99
end
1010

11-
const _fact_table128 = Vector{UInt128}(34)
11+
const _fact_table128 = Vector{UInt128}(uninitialized, 34)
1212
_fact_table128[1] = 1
1313
for n in 2:34
1414
_fact_table128[n] = _fact_table128[n-1] * n

base/deprecated.jl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ function Math.frexp(A::Array{<:AbstractFloat})
792792
"consider using dot-syntax to `broadcast` scalar `frexp` over `Array`s ",
793793
"instead, for example `frexp.(rand(4))`."), :frexp)
794794
F = similar(A)
795-
E = Array{Int}(size(A))
795+
E = Array{Int}(uninitialized, size(A))
796796
for (iF, iE, iA) in zip(eachindex(F), eachindex(E), eachindex(A))
797797
F[iF], E[iE] = frexp(A[iA])
798798
end
@@ -931,15 +931,15 @@ iteratoreltype(::Type{Task}) = EltypeUnknown()
931931
isempty(::Task) = error("isempty not defined for Tasks")
932932

933933
# Deprecate Array(T, dims...) in favor of proper type constructors
934-
@deprecate Array(::Type{T}, d::NTuple{N,Int}) where {T,N} Array{T}(d)
935-
@deprecate Array(::Type{T}, d::Int...) where {T} Array{T}(d...)
936-
@deprecate Array(::Type{T}, m::Int) where {T} Array{T}(m)
937-
@deprecate Array(::Type{T}, m::Int,n::Int) where {T} Array{T}(m,n)
938-
@deprecate Array(::Type{T}, m::Int,n::Int,o::Int) where {T} Array{T}(m,n,o)
939-
@deprecate Array(::Type{T}, d::Integer...) where {T} Array{T}(convert(Tuple{Vararg{Int}}, d))
940-
@deprecate Array(::Type{T}, m::Integer) where {T} Array{T}(Int(m))
941-
@deprecate Array(::Type{T}, m::Integer,n::Integer) where {T} Array{T}(Int(m),Int(n))
942-
@deprecate Array(::Type{T}, m::Integer,n::Integer,o::Integer) where {T} Array{T}(Int(m),Int(n),Int(o))
934+
@deprecate Array(::Type{T}, d::NTuple{N,Int}) where {T,N} Array{T}(uninitialized, d)
935+
@deprecate Array(::Type{T}, d::Int...) where {T} Array{T}(uninitialized, d...)
936+
@deprecate Array(::Type{T}, m::Int) where {T} Array{T}(uninitialized, m)
937+
@deprecate Array(::Type{T}, m::Int,n::Int) where {T} Array{T}(uninitialized, m,n)
938+
@deprecate Array(::Type{T}, m::Int,n::Int,o::Int) where {T} Array{T}(uninitialized, m,n,o)
939+
@deprecate Array(::Type{T}, d::Integer...) where {T} Array{T}(uninitialized, convert(Tuple{Vararg{Int}}, d))
940+
@deprecate Array(::Type{T}, m::Integer) where {T} Array{T}(uninitialized, Int(m))
941+
@deprecate Array(::Type{T}, m::Integer,n::Integer) where {T} Array{T}(uninitialized, Int(m),Int(n))
942+
@deprecate Array(::Type{T}, m::Integer,n::Integer,o::Integer) where {T} Array{T}(uninitialized, Int(m),Int(n),Int(o))
943943

944944
@noinline function is_intrinsic_expr(@nospecialize(x))
945945
Base.depwarn("is_intrinsic_expr is deprecated. There are no intrinsic functions anymore.", :is_intrinsic_expr)
@@ -1062,14 +1062,14 @@ end
10621062
## end of FloatRange
10631063

10641064
@noinline zero_arg_matrix_constructor(prefix::String) =
1065-
depwarn("$prefix() is deprecated, use $prefix(0, 0) instead.", :zero_arg_matrix_constructor)
1065+
depwarn("$prefix() is deprecated, use $prefix(uninitialized, 0, 0) instead.", :zero_arg_matrix_constructor)
10661066
function Matrix{T}() where T
10671067
zero_arg_matrix_constructor("Matrix{T}")
1068-
return Matrix{T}(0, 0)
1068+
return Matrix{T}(uninitialized, 0, 0)
10691069
end
10701070
function Matrix()
10711071
zero_arg_matrix_constructor("Matrix")
1072-
return Matrix(0, 0)
1072+
return Matrix(uninitialized, 0, 0)
10731073
end
10741074

10751075
for name in ("alnum", "alpha", "cntrl", "digit", "number", "graph",
@@ -1129,9 +1129,9 @@ import .LinAlg: cond
11291129

11301130
# PR #21359
11311131
import .Random: srand
1132-
@deprecate srand(r::MersenneTwister, filename::AbstractString, n::Integer=4) srand(r, read!(filename, Array{UInt32}(Int(n))))
1133-
@deprecate srand(filename::AbstractString, n::Integer=4) srand(read!(filename, Array{UInt32}(Int(n))))
1134-
@deprecate MersenneTwister(filename::AbstractString) srand(MersenneTwister(0), read!(filename, Array{UInt32}(Int(4))))
1132+
@deprecate srand(r::MersenneTwister, filename::AbstractString, n::Integer=4) srand(r, read!(filename, Vector{UInt32}(uninitialized, Int(n))))
1133+
@deprecate srand(filename::AbstractString, n::Integer=4) srand(read!(filename, Vector{UInt32}(uninitialized, Int(n))))
1134+
@deprecate MersenneTwister(filename::AbstractString) srand(MersenneTwister(0), read!(filename, Vector{UInt32}(uninitialized, Int(4))))
11351135

11361136
# PR #21974
11371137
@deprecate versioninfo(verbose::Bool) versioninfo(verbose=verbose)
@@ -1343,9 +1343,9 @@ import .LinAlg: lufact, lufact!, qrfact, qrfact!, cholfact, cholfact!
13431343

13441344
@deprecate read(s::IO, x::Ref) read!(s, x)
13451345

1346-
@deprecate read(s::IO, t::Type, d1::Int, dims::Int...) read!(s, Array{t}(tuple(d1,dims...)))
1347-
@deprecate read(s::IO, t::Type, d1::Integer, dims::Integer...) read!(s, Array{t}(convert(Tuple{Vararg{Int}},tuple(d1,dims...))))
1348-
@deprecate read(s::IO, t::Type, dims::Dims) read!(s, Array{t}(dims))
1346+
@deprecate read(s::IO, t::Type, d1::Int, dims::Int...) read!(s, Array{t}(uninitialized, tuple(d1,dims...)))
1347+
@deprecate read(s::IO, t::Type, d1::Integer, dims::Integer...) read!(s, Array{t}(uninitialized, convert(Tuple{Vararg{Int}},tuple(d1,dims...))))
1348+
@deprecate read(s::IO, t::Type, dims::Dims) read!(s, Array{t}(uninitialized, dims))
13491349

13501350
function CartesianRange(start::CartesianIndex{N}, stop::CartesianIndex{N}) where N
13511351
inds = map((f,l)->f:l, start.I, stop.I)

base/dict.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ mutable struct Dict{K,V} <: Associative{K,V}
101101

102102
function Dict{K,V}() where V where K
103103
n = 16
104-
new(zeros(UInt8,n), Array{K,1}(n), Array{V,1}(n), 0, 0, 0, 1, 0)
104+
new(zeros(UInt8,n), Vector{K}(uninitialized, n), Vector{V}(uninitialized, n), 0, 0, 0, 1, 0)
105105
end
106106
function Dict{K,V}(d::Dict{K,V}) where V where K
107107
new(copy(d.slots), copy(d.keys), copy(d.vals), d.ndel, d.count, d.age,
@@ -227,8 +227,8 @@ function rehash!(h::Dict{K,V}, newsz = length(h.keys)) where V where K
227227
end
228228

229229
slots = zeros(UInt8,newsz)
230-
keys = Array{K,1}(newsz)
231-
vals = Array{V,1}(newsz)
230+
keys = Vector{K}(uninitialized, newsz)
231+
vals = Vector{V}(uninitialized, newsz)
232232
age0 = h.age
233233
count = 0
234234
maxprobe = h.maxprobe

base/docs/core.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ..esc, ..push!, ..getindex, ..unsafe_load, ..Csize_t
77
function doc!(source::LineNumberNode, mod::Module, str, ex)
88
push!(DOCS, (mod, ex, str, source.file, source.line))
99
end
10-
const DOCS = Array{Any, 1}()
10+
const DOCS = Array{Any,1}()
1111

1212
isexpr(x, h) = isa(x, Expr) && x.head === h
1313

base/docs/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ function levenshtein(s1, s2)
271271
a, b = collect(s1), collect(s2)
272272
m = length(a)
273273
n = length(b)
274-
d = Matrix{Int}(m+1, n+1)
274+
d = Matrix{Int}(uninitialized, m+1, n+1)
275275

276276
d[1:m+1, 1] = 0:m
277277
d[1, 1:n+1] = 0:n

0 commit comments

Comments
 (0)