Skip to content

Commit

Permalink
Improve _field_types
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKlo committed Jan 6, 2025
1 parent d892204 commit d30d838
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/De/Deser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ function deser(::DictType, ::Type{T}, data::AbstractDict{K,D})::T where {T<:Abst
return target
end

_field_types(::Type{T}) where {T} = Tuple(fieldtype(T, x) for x in fieldnames(T))
_field_types(::Type{T}) where {T} = (fieldtype(T, x) for x in fieldnames(T))
_field_count(::Type{T}) where {T} = length(fieldnames(T))

@inline function eldeser(ct::Type, ft::Type, key::K, data::D) where {K,D}
try
Expand All @@ -371,7 +372,7 @@ _field_types(::Type{T}) where {T} = Tuple(fieldtype(T, x) for x in fieldnames(T)
end

function deser(::CustomType, ::Type{T}, data::AbstractVector{A})::T where {T<:Any,A<:Any}
target = Vector{Any}(undef, fieldcount(T))
target = Vector{Any}(undef, _field_count(T))
index::Int = 0
for (type, name) in zip(_field_types(T), fieldnames(T))
index += 1
Expand All @@ -384,7 +385,7 @@ function deser(::CustomType, ::Type{T}, data::AbstractVector{A})::T where {T<:An
end

function deser(::CustomType, ::Type{T}, data::AbstractDict{K,D})::T where {T<:Any,K<:Union{AbstractString,Symbol},D<:Any}
target = Vector{Any}(undef, fieldcount(T))
target = Vector{Any}(undef, _field_count(T))
index::Int = 0
for (type, name) in zip(_field_types(T), fieldnames(T))
index += 1
Expand All @@ -397,7 +398,7 @@ function deser(::CustomType, ::Type{T}, data::AbstractDict{K,D})::T where {T<:An
end

function deser(::CustomType, ::Type{T}, data::N)::T where {T<:Any,N<:NamedTuple}
target = Vector{Any}(undef, fieldcount(T))
target = Vector{Any}(undef, _field_count(T))
index::Int = 0
for (type, name) in zip(_field_types(T), fieldnames(T))
index += 1
Expand Down

0 comments on commit d30d838

Please sign in to comment.