From 23af3516ff7f400d0c2bf4404ad20139219c44e3 Mon Sep 17 00:00:00 2001 From: Jonas Isensee Date: Thu, 26 Oct 2023 14:28:50 +0200 Subject: [PATCH] fix iddicts --- src/data/specialcased_types.jl | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/data/specialcased_types.jl b/src/data/specialcased_types.jl index 5efcc4cc..5c08646c 100644 --- a/src/data/specialcased_types.jl +++ b/src/data/specialcased_types.jl @@ -244,20 +244,14 @@ writeas(::Type{Core.SimpleVector}) = Vector{Any} wconvert(::Type{Vector{Any}}, x::Core.SimpleVector) = collect(Any, x) rconvert(::Type{Core.SimpleVector}, x::Vector{Any}) = Core.svec(x...) -## Dicts - +## Standard Dictionary Types +# Custom dictionaries may need to store additional fields writeas(::Type{Dict{K,V}}) where {K,V} = Vector{Pair{K,V}} -writeas(::Type{IdDict{Any,Any}}) = Vector{Pair{Any,Any}} +writeas(::Type{IdDict{K,V}}) where {K,V} = Vector{Pair{K,V}} writeas(::Type{Base.ImmutableDict{K,V}}) where {K,V} = Vector{Pair{K,V}} + wconvert(::Type{Vector{Pair{K,V}}}, x::AbstractDict{K,V}) where {K,V} = collect(x) -function rconvert(::Type{T}, x::Vector{Pair{K,V}}) where {T<:AbstractDict,K,V} - d = T() - isa(d, Dict) && sizehint!(d::Dict, length(x)) - for (k,v) in x - d[k] = v - end - d -end +rconvert(::Type{T}, x::Vector{Pair{K,V}}) where {T<:Union{Dict,IdDict},K,V} = T(x) function rconvert(::Type{<:Base.ImmutableDict}, x::Vector{Pair{K,V}}) where {K,V} @assert !isempty(x)