Skip to content

Commit d7c56ba

Browse files
authored
Specialize tuple setindex to avoid ntuple-related performance regression. (#46050)
1 parent 017228a commit d7c56ba

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

base/tuple.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ function setindex(x::Tuple, v, i::Integer)
5555
_setindex(v, i, x...)
5656
end
5757

58-
function _setindex(v, i::Integer, args...)
58+
function _setindex(v, i::Integer, args::Vararg{Any,N}) where {N}
5959
@inline
60-
return ntuple(j -> ifelse(j == i, v, args[j]), length(args))
60+
return ntuple(j -> ifelse(j == i, v, args[j]), Val{N}())
6161
end
6262

6363

test/tuple.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,3 +754,6 @@ g42457(a, b) = Base.isequal(a, b) ? 1 : 2.0
754754
@test only(Base.return_types(g42457, (NTuple{3, Int}, Tuple))) === Union{Float64, Int}
755755
@test only(Base.return_types(g42457, (NTuple{3, Int}, NTuple))) === Union{Float64, Int}
756756
@test only(Base.return_types(g42457, (NTuple{3, Int}, NTuple{4}))) === Float64
757+
758+
# issue #46049: setindex(::Tuple) regression
759+
@inferred Base.setindex((1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16), 42, 1)

0 commit comments

Comments
 (0)