Skip to content

Commit

Permalink
DefaultsDict - correctness and performance tweaks for large numbers o…
Browse files Browse the repository at this point in the history
…f series (#126)
  • Loading branch information
BioTurboNick authored Oct 1, 2022
1 parent 0d57567 commit 948fdfb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion RecipesPipeline/src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ end
function Base.delete!(dd::DefaultsDict, k)
haskey(dd.explicit, k) && delete!(dd.explicit, k)
haskey(dd.defaults, k) && delete!(dd.defaults, k)
return dd
end
Base.length(dd::DefaultsDict) = length(union(keys(dd.explicit), keys(dd.defaults)))
function Base.iterate(dd::DefaultsDict)
Expand All @@ -50,7 +51,10 @@ isdefault(dd::DefaultsDict, k) = !is_explicit(dd, k) && haskey(dd.defaults, k)
Base.setindex!(dd::DefaultsDict, v, k) = dd.explicit[k] = v

# Reset to default value and return dict
reset_kw!(dd::DefaultsDict, k) = is_explicit(dd, k) ? delete!(dd.explicit, k) : dd
function reset_kw!(dd::DefaultsDict, k)
is_explicit(dd, k) && delete!(dd.explicit, k)
return dd
end
# Reset to default value and return old value
pop_kw!(dd::DefaultsDict, k) = is_explicit(dd, k) ? pop!(dd.explicit, k) : dd.defaults[k]
pop_kw!(dd::DefaultsDict, k, default) =
Expand Down

0 comments on commit 948fdfb

Please sign in to comment.