Skip to content

Commit a319ae4

Browse files
authored
Revert "Improve copyto! for short heterogeneous tuples (#39035)" (#39128)
This reverts commit b00e9f0, which has a 1/64 chance of failing tests.
1 parent 03957db commit a319ae4

File tree

3 files changed

+2
-58
lines changed

3 files changed

+2
-58
lines changed

base/abstractarray.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -831,14 +831,12 @@ end
831831

832832
## from general iterable to any array
833833

834-
@noinline throw_dest_too_short() =
835-
throw(ArgumentError("destination has fewer elements than required"))
836-
837834
function copyto!(dest::AbstractArray, src)
838835
destiter = eachindex(dest)
839836
y = iterate(destiter)
840837
for x in src
841-
y === nothing && throw_dest_too_short()
838+
y === nothing &&
839+
throw(ArgumentError("destination has fewer elements than required"))
842840
dest[y[1]] = x
843841
y = iterate(destiter, y[2])
844842
end

base/ntuple.jl

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -91,47 +91,3 @@ end
9191
(t..., fill(val, N-M)...)
9292
end
9393
end
94-
95-
# Specializations for copyto! of various `NTuple`s
96-
function check_inds_compatible(dest::AbstractArray, src::Tuple)
97-
length(dest) >= length(src) || throw_dest_too_short()
98-
end
99-
100-
function _copyto_generated!(dest::AbstractArray, src::NTuple{N, Any}) where N
101-
if @generated
102-
ret = quote
103-
check_inds_compatible(dest, src)
104-
idxs = eachindex(dest)
105-
end
106-
state = ()
107-
for n in 1:N
108-
append!(ret.args, (quote
109-
ind, state = iterate(idxs, $(state...))
110-
@inbounds dest[ind] = src[$n]
111-
end).args)
112-
state = (:state,)
113-
end
114-
push!(ret.args, :(return dest))
115-
ret
116-
else
117-
length(src) == 0 && return dest
118-
return copyto!(dest, firstindex(dest), src, firstindex(src))
119-
end
120-
end
121-
122-
# Non-homogeneous tuples
123-
function copyto!(dest::AbstractArray, src::Tuple)
124-
if length(src) < 10
125-
# Manual optimization for short tuples
126-
# TODO: Better support for homogeneous tuple tails
127-
return _copyto_generated!(dest, src)
128-
else
129-
return copyto!(dest, firstindex(dest), src, firstindex(src))
130-
end
131-
end
132-
133-
# Specialization for homogeneous tuples
134-
function copyto!(dest::AbstractArray, src::Tuple{Vararg{T}} where T)
135-
length(src) == 0 && return dest
136-
copyto!(dest, firstindex(dest), src, firstindex(src))
137-
end

test/abstractarray.jl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,13 +1263,3 @@ Base.pushfirst!(tpa::TestPushArray{T}, a::T) where T = pushfirst!(tpa.data, a)
12631263
pushfirst!(tpa, 6, 5, 4, 3, 2)
12641264
@test tpa.data == reverse(collect(1:6))
12651265
end
1266-
1267-
@testset "copyto! with tuple" begin
1268-
randtype(n) = rand(Bool) ? 1.0 : 2
1269-
@test copyto!(fill(0.0, 100), ntuple(randtype, 100))[end] != 0.0
1270-
@test copyto!(fill(0.0, 100), ntuple(x->1.0, 100))[end] != 0.0
1271-
@test copyto!(fill(0.0, 100), ntuple(randtype, 50))[end] == 0.0
1272-
@test_throws BoundsError copyto!(fill(0.0, 50), ntuple(randtype, 100))
1273-
@test_throws BoundsError copyto!(fill(0.0, 50), ntuple(x->1.0, 100))
1274-
@test_throws ArgumentError copyto!(fill(0.0, 5), ntuple(randtype, 7))
1275-
end

0 commit comments

Comments
 (0)