From 9c9eb683b56d7839f223c5526bdfbbedc0471280 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Sat, 25 Nov 2017 09:02:35 -0800 Subject: [PATCH] Replace Array{...}(shape...)-like calls in base/[e-k]*.jl. (#24757) --- base/Enums.jl | 2 +- base/env.jl | 2 +- base/error.jl | 2 +- base/essentials.jl | 8 ++++---- base/file.jl | 10 +++++----- base/float.jl | 4 ++-- base/grisu/bignums.jl | 2 +- base/grisu/fastprecision.jl | 2 +- base/grisu/fastshortest.jl | 2 +- base/grisu/grisu.jl | 2 +- base/inference.jl | 20 ++++++++++---------- base/io.jl | 4 ++-- base/iostream.jl | 4 ++-- base/iterators.jl | 2 +- base/libc.jl | 4 ++-- base/libdl.jl | 2 +- base/libgit2/reference.jl | 2 +- 17 files changed, 37 insertions(+), 37 deletions(-) diff --git a/base/Enums.jl b/base/Enums.jl index b10ff6cf79039..83c9afab5bdb3 100644 --- a/base/Enums.jl +++ b/base/Enums.jl @@ -65,7 +65,7 @@ macro enum(T, syms...) elseif !isa(T, Symbol) throw(ArgumentError("invalid type expression for enum $T")) end - vals = Vector{Tuple{Symbol,Integer}}(0) + vals = Vector{Tuple{Symbol,Integer}}() lo = hi = 0 i = zero(basetype) hasexpr = false diff --git a/base/env.jl b/base/env.jl index 718c500257665..3b171e15f60f2 100644 --- a/base/env.jl +++ b/base/env.jl @@ -98,7 +98,7 @@ if Sys.iswindows() pos = block[1] blk = block[2] len = ccall(:wcslen, UInt, (Ptr{UInt16},), pos) - buf = Vector{UInt16}(len) + buf = Vector{UInt16}(uninitialized, len) @gc_preserve buf unsafe_copy!(pointer(buf), pos, len) env = transcode(String, buf) m = match(r"^(=?[^=]+)=(.*)$"s, env) diff --git a/base/error.jl b/base/error.jl index cb4838e956b0c..3ec59e5aa7c23 100644 --- a/base/error.jl +++ b/base/error.jl @@ -60,7 +60,7 @@ end # convert dual arrays (ips, interpreter_frames) to a single array of locations function _reformat_bt(bt, bt2) - ret = Array{Union{InterpreterIP,Ptr{Void}},1}() + ret = Vector{Union{InterpreterIP,Ptr{Void}}}() i, j = 1, 1 while i <= length(bt) ip = bt[i]::Ptr{Void} diff --git a/base/essentials.jl b/base/essentials.jl index 5f3977c8d7e55..a3f3f444ba8d4 100644 --- a/base/essentials.jl +++ b/base/essentials.jl @@ -370,7 +370,7 @@ function append_any(xs...) # used by apply() and quote # must be a separate function from append(), since apply() needs this # exact function. - out = Vector{Any}(4) + out = Vector{Any}(uninitialized, 4) l = 4 i = 1 for x in xs @@ -627,7 +627,7 @@ Val(x) = (@_pure_meta; Val{x}()) # used by keyword arg call lowering function vector_any(@nospecialize xs...) n = length(xs) - a = Vector{Any}(n) + a = Vector{Any}(uninitialized, n) @inbounds for i = 1:n Core.arrayset(false, a, xs[i], i) end @@ -636,7 +636,7 @@ end function as_kwargs(xs::Union{AbstractArray,Associative}) n = length(xs) - to = Vector{Any}(n*2) + to = Vector{Any}(uninitialized, n*2) i = 1 for (k, v) in xs to[i] = k::Symbol @@ -647,7 +647,7 @@ function as_kwargs(xs::Union{AbstractArray,Associative}) end function as_kwargs(xs) - to = Vector{Any}(0) + to = Vector{Any}() for (k, v) in xs ccall(:jl_array_ptr_1d_push2, Void, (Any, Any, Any), to, k::Symbol, v) end diff --git a/base/file.jl b/base/file.jl index 4ab1cf08eafc6..bdd4027925c79 100644 --- a/base/file.jl +++ b/base/file.jl @@ -35,7 +35,7 @@ export Get the current working directory. """ function pwd() - b = Vector{UInt8}(1024) + b = Vector{UInt8}(uninitialized, 1024) len = Ref{Csize_t}(length(b)) uv_error(:getcwd, ccall(:uv_cwd, Cint, (Ptr{UInt8}, Ptr{Csize_t}), b, len)) String(b[1:len[]]) @@ -257,7 +257,7 @@ end if Sys.iswindows() function tempdir() - temppath = Vector{UInt16}(32767) + temppath = Vector{UInt16}(uninitialized, 32767) lentemppath = ccall(:GetTempPathW,stdcall,UInt32,(UInt32,Ptr{UInt16}),length(temppath),temppath) if lentemppath >= length(temppath) || lentemppath == 0 error("GetTempPath failed: $(Libc.FormatMessage())") @@ -269,7 +269,7 @@ tempname(uunique::UInt32=UInt32(0)) = tempname(tempdir(), uunique) const temp_prefix = cwstring("jl_") function tempname(temppath::AbstractString,uunique::UInt32) tempp = cwstring(temppath) - tname = Vector{UInt16}(32767) + tname = Vector{UInt16}(uninitialized, 32767) uunique = ccall(:GetTempFileNameW,stdcall,UInt32,(Ptr{UInt16},Ptr{UInt16},UInt32,Ptr{UInt16}), tempp,temp_prefix,uunique,tname) lentname = findfirst(iszero,tname)-1 if uunique == 0 || lentname <= 0 @@ -465,8 +465,8 @@ function walkdir(root; topdown=true, follow_symlinks=false, onerror=throw) close(chnl) return chnl end - dirs = Vector{eltype(content)}(0) - files = Vector{eltype(content)}(0) + dirs = Vector{eltype(content)}() + files = Vector{eltype(content)}() for name in content if isdir(joinpath(root, name)) push!(dirs, name) diff --git a/base/float.jl b/base/float.jl index 6d1d6efca647d..9ecd70eb5a976 100644 --- a/base/float.jl +++ b/base/float.jl @@ -203,8 +203,8 @@ end # "Fast Half Float Conversion" by Jeroen van der Zijp # ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf -const basetable = Vector{UInt16}(512) -const shifttable = Vector{UInt8}(512) +const basetable = Vector{UInt16}(uninitialized, 512) +const shifttable = Vector{UInt8}(uninitialized, 512) for i = 0:255 e = i - 127 diff --git a/base/grisu/bignums.jl b/base/grisu/bignums.jl index 7398028b81202..54a948da473e7 100644 --- a/base/grisu/bignums.jl +++ b/base/grisu/bignums.jl @@ -54,7 +54,7 @@ mutable struct Bignum used_digits::Int32 exponent::Int32 function Bignum() - bigits = Vector{UInt32}(kBigitCapacity) + bigits = Vector{UInt32}(uninitialized, kBigitCapacity) @inbounds for i = 1:kBigitCapacity bigits[i] = 0 end diff --git a/base/grisu/fastprecision.jl b/base/grisu/fastprecision.jl index 3d737b1d13eb6..b54fd2397b360 100644 --- a/base/grisu/fastprecision.jl +++ b/base/grisu/fastprecision.jl @@ -87,7 +87,7 @@ function digitgen(w,buffer,requested_digits=1000) return r, kappa, len end -function fastprecision(v, requested_digits, buffer = Vector{UInt8}(100)) +function fastprecision(v, requested_digits, buffer = Vector{UInt8}(uninitialized, 100)) f = normalize(Float64(v)) ten_mk_min_exp = kMinExp - (f.e + FloatSignificandSize) ten_mk_max_exp = kMaxExp - (f.e + FloatSignificandSize) diff --git a/base/grisu/fastshortest.jl b/base/grisu/fastshortest.jl index c7b70dea84acc..b619b0b56c9a6 100644 --- a/base/grisu/fastshortest.jl +++ b/base/grisu/fastshortest.jl @@ -102,7 +102,7 @@ function digitgen(low,w,high,buffer) end end -function fastshortest(v, buffer = Vector{UInt8}(17)) +function fastshortest(v, buffer = Vector{UInt8}(uninitialized, 17)) f = normalize(Float64(v)) bound_minus, bound_plus = normalizedbound(v) ten_mk_min_exp = kMinExp - (f.e + FloatSignificandSize) diff --git a/base/grisu/grisu.jl b/base/grisu/grisu.jl index 64942d2775ba0..72748e1701638 100644 --- a/base/grisu/grisu.jl +++ b/base/grisu/grisu.jl @@ -9,7 +9,7 @@ const SHORTEST = 1 const FIXED = 2 const PRECISION = 3 -const DIGITS = Vector{UInt8}(309+17) +const DIGITS = Vector{UInt8}(uninitialized, 309+17) include(joinpath("grisu", "float.jl")) include(joinpath("grisu", "fastshortest.jl")) diff --git a/base/inference.jl b/base/inference.jl index de0f584ecdda8..c229a00b63a0f 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -511,11 +511,11 @@ iskindtype(@nospecialize t) = (t === DataType || t === UnionAll || t === Union | const IInf = typemax(Int) # integer infinity const n_ifunc = reinterpret(Int32, arraylen) + 1 -const t_ifunc = Array{Tuple{Int, Int, Any}, 1}(n_ifunc) -const t_ifunc_cost = Array{Int, 1}(n_ifunc) -const t_ffunc_key = Array{Any, 1}(0) -const t_ffunc_val = Array{Tuple{Int, Int, Any}, 1}(0) -const t_ffunc_cost = Array{Int, 1}(0) +const t_ifunc = Vector{Tuple{Int, Int, Any}}(uninitialized, n_ifunc) +const t_ifunc_cost = Vector{Int}(uninitialized, n_ifunc) +const t_ffunc_key = Vector{Any}() +const t_ffunc_val = Vector{Tuple{Int, Int, Any}}() +const t_ffunc_cost = Vector{Int}() function add_tfunc(f::IntrinsicFunction, minarg::Int, maxarg::Int, @nospecialize(tfunc), cost::Int) idx = reinterpret(Int32, f) + 1 t_ifunc[idx] = (minarg, maxarg, tfunc) @@ -4260,7 +4260,7 @@ function linearize_args!(args::Vector{Any}, atypes::Vector{Any}, stmts::Vector{A # linearize the IR by moving the arguments to SSA position na = length(args) @assert length(atypes) == na - newargs = Vector{Any}(na) + newargs = Vector{Any}(uninitialized, na) for i = na:-1:1 aei = args[i] ti = atypes[i] @@ -5272,7 +5272,7 @@ function inlining_pass(e::Expr, sv::OptimizationState, stmts::Vector{Any}, ins, end for ninline = 1:100 - ata = Vector{Any}(length(e.args)) + ata = Vector{Any}(uninitialized, length(e.args)) ata[1] = ft for i = 2:length(e.args) a = exprtype(e.args[i], sv.src, sv.mod) @@ -5301,7 +5301,7 @@ function inlining_pass(e::Expr, sv::OptimizationState, stmts::Vector{Any}, ins, if f === _apply na = length(e.args) - newargs = Vector{Any}(na-2) + newargs = Vector{Any}(uninitialized, na-2) newstmts = Any[] effect_free_upto = 0 for i = 3:na @@ -6025,10 +6025,10 @@ function alloc_elim_pass!(sv::OptimizationState) end end else - vals = Vector{Any}(nv) + vals = Vector{Any}(uninitialized, nv) local new_slots::Vector{Int} if !is_ssa - new_slots = Vector{Int}(nv) + new_slots = Vector{Int}(uninitialized, nv) end for j=1:nv tupelt = tup[j+1] diff --git a/base/io.jl b/base/io.jl index a948fb320f496..46e6564e6a680 100644 --- a/base/io.jl +++ b/base/io.jl @@ -637,7 +637,7 @@ Read at most `nb` bytes from `s`, returning a `Vector{UInt8}` of the bytes read. function read(s::IO, nb::Integer = typemax(Int)) # Let readbytes! grow the array progressively by default # instead of taking of risk of over-allocating - b = Vector{UInt8}(nb == typemax(Int) ? 1024 : nb) + b = Vector{UInt8}(uninitialized, nb == typemax(Int) ? 1024 : nb) nr = readbytes!(s, b, nb) return resize!(b, nr) end @@ -791,7 +791,7 @@ passing them as the second argument. function countlines(io::IO, eol::Char='\n') isascii(eol) || throw(ArgumentError("only ASCII line terminators are supported")) aeol = UInt8(eol) - a = Vector{UInt8}(8192) + a = Vector{UInt8}(uninitialized, 8192) nl = 0 while !eof(io) nb = readbytes!(io, a) diff --git a/base/iostream.jl b/base/iostream.jl index 5659fd12357fb..a8443c67aee2a 100644 --- a/base/iostream.jl +++ b/base/iostream.jl @@ -211,7 +211,7 @@ end # num bytes available without blocking nb_available(s::IOStream) = ccall(:jl_nb_available, Int32, (Ptr{Void},), s.ios) -readavailable(s::IOStream) = read!(s, Vector{UInt8}(nb_available(s))) +readavailable(s::IOStream) = read!(s, Vector{UInt8}(uninitialized, nb_available(s))) function read(s::IOStream, ::Type{UInt8}) b = ccall(:ios_getc, Cint, (Ptr{Void},), s.ios) @@ -330,7 +330,7 @@ requested bytes, until an error or end-of-file occurs. If `all` is `false`, at m all stream types support the `all` option. """ function read(s::IOStream, nb::Integer; all::Bool=true) - b = Array{UInt8,1}(nb) + b = Vector{UInt8}(uninitialized, nb) nr = readbytes!(s, b, nb, all=all) resize!(b, nr) end diff --git a/base/iterators.jl b/base/iterators.jl index ea65b8f59edd1..634f5ccf99cf5 100644 --- a/base/iterators.jl +++ b/base/iterators.jl @@ -895,7 +895,7 @@ function next(itr::PartitionIterator{<:Vector}, state) end function next(itr::PartitionIterator, state) - v = Vector{eltype(itr.c)}(itr.n) + v = Vector{eltype(itr.c)}(uninitialized, itr.n) i = 0 while !done(itr.c, state) && i < itr.n i += 1 diff --git a/base/libc.jl b/base/libc.jl index b6f76e3cb749f..c4577a5bb0528 100644 --- a/base/libc.jl +++ b/base/libc.jl @@ -245,7 +245,7 @@ getpid() = ccall(:jl_getpid, Int32, ()) Get the local machine's host name. """ function gethostname() - hn = Vector{UInt8}(256) + hn = Vector{UInt8}(uninitialized, 256) err = @static if Sys.iswindows() ccall(:gethostname, stdcall, Int32, (Ptr{UInt8}, UInt32), hn, length(hn)) else @@ -307,7 +307,7 @@ if Sys.iswindows() C_NULL, e, 0, lpMsgBuf, 0, C_NULL) p = lpMsgBuf[] len == 0 && return "" - buf = Vector{UInt16}(len) + buf = Vector{UInt16}(uninitialized, len) Base.@gc_preserve buf unsafe_copy!(pointer(buf), p, len) ccall(:LocalFree, stdcall, Ptr{Void}, (Ptr{Void},), p) return transcode(String, buf) diff --git a/base/libdl.jl b/base/libdl.jl index 9081709b971fb..a63feecc4915e 100644 --- a/base/libdl.jl +++ b/base/libdl.jl @@ -234,7 +234,7 @@ if Sys.isbsd() && !Sys.isapple() end # bsd family function dllist() - dynamic_libraries = Vector{AbstractString}(0) + dynamic_libraries = Vector{AbstractString}() @static if Sys.islinux() callback = cfunction(dl_phdr_info_callback, Cint, diff --git a/base/libgit2/reference.jl b/base/libgit2/reference.jl index 634658c979f3c..e703d215d3643 100644 --- a/base/libgit2/reference.jl +++ b/base/libgit2/reference.jl @@ -350,7 +350,7 @@ function Base.map(f::Function, bi::GitBranchIter) while !done(bi, s) val = f(s[1:2]) if res === nothing - res = Vector{typeof(val)}(0) + res = Vector{typeof(val)}() end push!(res, val) val, s = next(bi, s)