Skip to content

Commit

Permalink
Replaced enumerate with a manual counter
Browse files Browse the repository at this point in the history
  • Loading branch information
gryumov committed Jan 3, 2025
1 parent 5e02068 commit 06e607f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/De/Deser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -365,33 +365,39 @@ end
end

function deser(::CustomType, ::Type{T}, data::AbstractVector{A})::T where {T<:Any,A<:Any}
target = Any[]
for (index, type) in enumerate(fieldtypes(T))
target = Vector{Any}(undef, fieldcount(T))
index::Int = 0
for type in fieldtypes(T)
index += 1
val = get(data, index, nulltype(type))
val = isempty(T, val) ? nulltype(type) : val
push!(target, eldeser(T, type, index, val))
target[index] = eldeser(T, type, index, val)
end
return T(target...)
end

function deser(::CustomType, ::Type{T}, data::AbstractDict{K,D})::T where {T<:Any,K<:Union{AbstractString,Symbol},D<:Any}
target = Any[]
target = Vector{Any}(undef, fieldcount(T))
index::Int = 0
for (type, name) in zip(fieldtypes(T), fieldnames(T))
index += 1
key = custom_name(T, Val(name))
val = get(data, K(key), default_value(T, Val(name)))
val = isnothing(val) || ismissing(val) || isempty(T, val) ? nulltype(type) : val
push!(target, eldeser(T, type, key, val))
target[index] = eldeser(T, type, key, val)
end
return T(target...)
end

function deser(::CustomType, ::Type{T}, data::N)::T where {T<:Any,N<:NamedTuple}
target = Any[]
target = Vector{Any}(undef, fieldcount(T))
index::Int = 0
for (type, name) in zip(fieldtypes(T), fieldnames(T))
index += 1
key = custom_name(T, Val(name))
val = get(data, key, default_value(T, Val(name)))
val = isnothing(val) || ismissing(val) || isempty(T, val) ? nulltype(type) : val
push!(target, eldeser(T, type, key, val))
target[index] = eldeser(T, type, key, val)
end
return T(target...)
end

0 comments on commit 06e607f

Please sign in to comment.