From 06e607fd843398ab4a7c663e6f3a1ad9f0d654a2 Mon Sep 17 00:00:00 2001 From: stanislav Date: Fri, 3 Jan 2025 18:35:19 +0300 Subject: [PATCH] Replaced enumerate with a manual counter --- src/De/Deser.jl | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/De/Deser.jl b/src/De/Deser.jl index 69df6f2..b12185c 100644 --- a/src/De/Deser.jl +++ b/src/De/Deser.jl @@ -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