Skip to content

Commit 368ae19

Browse files
authored
Backports more code quality PRs to v1.12 (#60469)
- [x] #60461 - [x] #60465 - [x] #60466
2 parents 2c50cb0 + 798e447 commit 368ae19

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

base/array.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ julia> collect(Float64, 1:2:5)
641641
collect(::Type{T}, itr) where {T} = _collect(T, itr, IteratorSize(itr))
642642

643643
_collect(::Type{T}, itr, isz::Union{HasLength,HasShape}) where {T} =
644-
copyto!(_array_for(T, isz, _similar_shape(itr, isz)), itr)
644+
copyto!(_array_for_inner(T, isz, _similar_shape(itr, isz)), itr)
645645
function _collect(::Type{T}, itr, isz::SizeUnknown) where T
646646
a = Vector{T}()
647647
for x in itr
@@ -665,12 +665,12 @@ _similar_for(c::AbstractArray, ::Type{T}, itr, ::HasShape, axs) where {T} =
665665
similar(c, T, axs)
666666

667667
# make a collection appropriate for collecting `itr::Generator`
668-
_array_for(::Type{T}, ::SizeUnknown, ::Nothing) where {T} = Vector{T}(undef, 0)
669-
_array_for(::Type{T}, ::HasLength, len::Integer) where {T} = Vector{T}(undef, Int(len))
670-
_array_for(::Type{T}, ::HasShape{N}, axs) where {T,N} = similar(Array{T,N}, axs)
668+
_array_for_inner(::Type{T}, ::SizeUnknown, ::Nothing) where {T} = Vector{T}(undef, 0)
669+
_array_for_inner(::Type{T}, ::HasLength, len::Integer) where {T} = Vector{T}(undef, Int(len))
670+
_array_for_inner(::Type{T}, ::HasShape{N}, axs) where {T,N} = similar(Array{T,N}, axs)
671671

672672
# used by syntax lowering for simple typed comprehensions
673-
_array_for(::Type{T}, itr, isz) where {T} = _array_for(T, isz, _similar_shape(itr, isz))
673+
_array_for(::Type{T}, itr, isz) where {T} = _array_for_inner(T, isz, _similar_shape(itr, isz))
674674

675675

676676
"""
@@ -789,10 +789,10 @@ function collect(itr::Generator)
789789
shp = _similar_shape(itr, isz)
790790
y = iterate(itr)
791791
if y === nothing
792-
return _array_for(et, isz, shp)
792+
return _array_for_inner(et, isz, shp)
793793
end
794794
v1, st = y
795-
dest = _array_for(typeof(v1), isz, shp)
795+
dest = _array_for_inner(typeof(v1), isz, shp)
796796
# The typeassert gives inference a helping hand on the element type and dimensionality
797797
# (work-around for #28382)
798798
et′ = et <: Type ? Type : et

base/file.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,22 +1267,19 @@ function rename(oldpath::AbstractString, newpath::AbstractString)
12671267
end
12681268

12691269
function sendfile(src::AbstractString, dst::AbstractString)
1270-
src_open = false
1271-
dst_open = false
1272-
local src_file, dst_file
1270+
src_file = nothing
1271+
dst_file = nothing
12731272
try
12741273
src_file = open(src, JL_O_RDONLY)
1275-
src_open = true
12761274
dst_file = open(dst, JL_O_CREAT | JL_O_TRUNC | JL_O_WRONLY, filemode(src_file))
1277-
dst_open = true
12781275

12791276
bytes = filesize(stat(src_file))
12801277
sendfile(dst_file, src_file, Int64(0), Int(bytes))
12811278
finally
1282-
if src_open && isopen(src_file)
1279+
if src_file !== nothing && isopen(src_file)
12831280
close(src_file)
12841281
end
1285-
if dst_open && isopen(dst_file)
1282+
if dst_file !== nothing && isopen(dst_file)
12861283
close(dst_file)
12871284
end
12881285
end

base/toml_parser.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,8 @@ function parse_array(l::Parser{Dates})::Err{Vector} where Dates
716716
copyto_typed!(new, array)
717717
elseif T === Union{}
718718
new = Any[]
719-
elseif (T === TOMLDict) || (T == BigInt) || (T === UInt128) || (T === Int128) || (T <: Vector) ||
720-
(T === Dates.Date) || (T === Dates.Time) || (T === Dates.DateTime)
719+
elseif (T === TOMLDict) || (T === BigInt) || (T === UInt128) || (T === Int128) || (T <: Vector) ||
720+
(Dates !== nothing && ((T === Dates.Date) || (T === Dates.Time) || (T === Dates.DateTime)))
721721
# do nothing, leave as Vector{Any}
722722
new = array
723723
else @assert false end

0 commit comments

Comments
 (0)