From c745b4785caf6f8ceb11b3822d748b81ba91d2be Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Mon, 1 Jun 2026 13:26:16 +0200 Subject: [PATCH] dicts: improve performance for non-concrete values and keys --- src/ordered_robin_dict.jl | 8 ++++---- src/swiss_dict.jl | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ordered_robin_dict.jl b/src/ordered_robin_dict.jl index e8b3b0321..7ab0bf3e2 100644 --- a/src/ordered_robin_dict.jl +++ b/src/ordered_robin_dict.jl @@ -430,18 +430,18 @@ function get_next_filled_index(h::OrderedRobinDict, index) return -1 end -Base.@propagate_inbounds function Base.iterate(h::OrderedRobinDict) +Base.@propagate_inbounds function Base.iterate(h::OrderedRobinDict{K,V}) where {K,V} isempty(h) && return nothing check_for_rehash(h) && rehash!(h) index = get_first_filled_index(h) - return (Pair(h.keys[index], h.vals[index]), index+1) + @inbounds return (Pair{K,V}(h.keys[index], h.vals[index]), index+1) end -Base.@propagate_inbounds function Base.iterate(h::OrderedRobinDict, i) +Base.@propagate_inbounds function Base.iterate(h::OrderedRobinDict{K,V}, i) where {K,V} length(h.keys) < i && return nothing index = get_next_filled_index(h, i) (index < 0) && return nothing - return (Pair(h.keys[index], h.vals[index]), index+1) + @inbounds return (Pair{K,V}(h.keys[index], h.vals[index]), index+1) end Base.filter!(f, d::Union{RobinDict, OrderedRobinDict}) = Base.filter_in_one_pass!(f, d) diff --git a/src/swiss_dict.jl b/src/swiss_dict.jl index 25be7c5c7..16cdc1144 100644 --- a/src/swiss_dict.jl +++ b/src/swiss_dict.jl @@ -636,11 +636,11 @@ function Base.delete!(h::SwissDict, key) return h end -Base.@propagate_inbounds function Base.iterate(h::SwissDict, state = h.idxfloor) +Base.@propagate_inbounds function Base.iterate(h::SwissDict{K,V}, state = h.idxfloor) where {K,V} is = _iterslots(h, state) is === nothing && return nothing i, s = is - @inbounds p = h.keys[i] => h.vals[i] + @inbounds p = Pair{K,V}(h.keys[i], h.vals[i]) return (p, s) end