Skip to content

Commit

Permalink
define core NamedTuple constructor without generated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Feb 7, 2019
1 parent 7deecac commit e456a72
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -548,33 +548,8 @@ NamedTuple{names}(args::Tuple) where {names} = NamedTuple{names,typeof(args)}(ar

using .Intrinsics: sle_int, add_int

macro generated()
return Expr(:generated)
end

function NamedTuple{names,T}(args::T) where {names, T <: Tuple}
if @generated
N = nfields(names)
flds = Array{Any,1}(undef, N)
i = 1
while sle_int(i, N)
arrayset(false, flds, :(getfield(args, $i)), i)
i = add_int(i, 1)
end
Expr(:new, :(NamedTuple{names,T}), flds...)
else
N = nfields(names)
NT = NamedTuple{names,T}
flds = Array{Any,1}(undef, N)
i = 1
while sle_int(i, N)
arrayset(false, flds, getfield(args, i), i)
i = add_int(i, 1)
end
ccall(:jl_new_structv, Any, (Any, Ptr{Cvoid}, UInt32), NT,
ccall(:jl_array_ptr, Ptr{Cvoid}, (Any,), flds), toUInt32(N))::NT
end
end
eval(Core, :(NamedTuple{names,T}(args::T) where {names, T <: Tuple} =
$(Expr(:splatnew, :(NamedTuple{names,T}), :args))))

# constructors for built-in types

Expand Down

0 comments on commit e456a72

Please sign in to comment.