Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/ordered_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -451,28 +451,28 @@ function delete!(h::OrderedDict, key)
return h
end

function iterate(t::OrderedDict)
function iterate(t::OrderedDict{K,V}) where {K,V}
t.ndel > 0 && rehash!(t)
length(t.keys) < 1 && return nothing
return (Pair(t.keys[1], t.vals[1]), 2)
Copy link
Copy Markdown
Member

@timholy timholy Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you're just copying what was already there, but I wonder about switching to first and similarly checkbounds(Bool, t.keys, i) for the i-generic one; those are more precisely aligned to what's actually being tested. It's the same thing for Vector, of course. Up to you, I'd merge this without that change.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather minimize the diff in this PR to focus on the specifics that changed the behavior.

@inbounds return (Pair{K,V}(t.keys[1], t.vals[1]), 2)
end
function iterate(t::OrderedDict, i)
function iterate(t::OrderedDict{K,V}, i) where {K,V}
length(t.keys) < i && return nothing
return (Pair(t.keys[i], t.vals[i]), i+1)
@inbounds return (Pair{K,V}(t.keys[i], t.vals[i]), i+1)
end

# lazy reverse iteration
function iterate(rt::Iterators.Reverse{<:OrderedDict})
function iterate(rt::Iterators.Reverse{<:OrderedDict{K,V}}) where {K,V}
t = rt.itr
t.ndel > 0 && rehash!(t)
n = length(t.keys)
n < 1 && return nothing
return (Pair(t.keys[n], t.vals[n]), n - 1)
@inbounds return (Pair{K,V}(t.keys[n], t.vals[n]), n - 1)
end
function iterate(rt::Iterators.Reverse{<:OrderedDict}, i)
function iterate(rt::Iterators.Reverse{<:OrderedDict{K,V}}, i) where {K,V}
t = rt.itr
i < 1 && return nothing
return (Pair(t.keys[i], t.vals[i]), i - 1)
@inbounds return (Pair{K,V}(t.keys[i], t.vals[i]), i - 1)
end


Expand Down
Loading