Skip to content

Commit

Permalink
Faster conversion from NamedTuple to Tuple (#26025)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyferris authored and JeffBezanson committed Feb 14, 2018
1 parent 8f30d37 commit 45e9b82
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions base/namedtuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ function convert(::Type{NamedTuple{names,T}}, nt::NamedTuple{names}) where {name
NamedTuple{names,T}(T(nt))
end

function Tuple(nt::NamedTuple{names}) where {names}
if @generated
return Expr(:tuple, Any[:(getfield(nt, $(QuoteNode(n)))) for n in names]...)
else
return tuple(nt...)
end
end
(::Type{T})(nt::NamedTuple) where {T <: Tuple} = convert(T, Tuple(nt))

function show(io::IO, t::NamedTuple)
n = nfields(t)
for i = 1:n
Expand Down

0 comments on commit 45e9b82

Please sign in to comment.