diff --git a/base/array.jl b/base/array.jl index 648fedd5036e1..90b0ac8dc12fa 100644 --- a/base/array.jl +++ b/base/array.jl @@ -728,9 +728,16 @@ function _collect(cont, itr, ::HasEltype, isz::SizeUnknown) return a end -_collect_indices(::Tuple{}, A) = copyto!(Array{eltype(A),0}(undef), A) -_collect_indices(indsA::Tuple{Vararg{OneTo}}, A) = - copyto!(Array{eltype(A)}(undef, length.(indsA)), A) +function _collect_indices(::Tuple{}, A) + dest = Array{eltype(A),0}(undef) + isempty(A) && return dest + return copyto_unaliased!(IndexStyle(dest), dest, IndexStyle(A), A) +end +function _collect_indices(indsA::Tuple{Vararg{OneTo}}, A) + dest = Array{eltype(A)}(undef, length.(indsA)) + isempty(A) && return dest + return copyto_unaliased!(IndexStyle(dest), dest, IndexStyle(A), A) +end function _collect_indices(indsA, A) B = Array{eltype(A)}(undef, length.(indsA)) copyto!(B, CartesianIndices(axes(B)), A, CartesianIndices(indsA))