Skip to content

Commit

Permalink
fix #31760, regression in Dict iterate
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Apr 18, 2019
1 parent c83e312 commit 833269c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -662,17 +662,17 @@ function skip_deleted(h::Dict, i)
return i
end
end
return nothing
return 0
end
function skip_deleted_floor!(h::Dict)
idx = skip_deleted(h, h.idxfloor)
if idx !== nothing
if idx != 0
h.idxfloor = idx
end
idx
end

@propagate_inbounds _iterate(t::Dict{K,V}, i) where {K,V} = i === nothing ? nothing : (Pair{K,V}(t.keys[i],t.vals[i]), i == typemax(Int) ? nothing : i+1)
@propagate_inbounds _iterate(t::Dict{K,V}, i) where {K,V} = i == 0 ? nothing : (Pair{K,V}(t.keys[i],t.vals[i]), i == typemax(Int) ? 0 : i+1)
@propagate_inbounds function iterate(t::Dict)
_iterate(t, skip_deleted_floor!(t))
end
Expand All @@ -681,12 +681,12 @@ end
isempty(t::Dict) = (t.count == 0)
length(t::Dict) = t.count

@propagate_inbounds function Base.iterate(v::T, i::Union{Int,Nothing}=v.dict.idxfloor) where T <: Union{KeySet{<:Any, <:Dict}, ValueIterator{<:Dict}}
i === nothing && return nothing # This is to catch nothing returned when i = typemax
@propagate_inbounds function Base.iterate(v::T, i::Int = v.dict.idxfloor) where T <: Union{KeySet{<:Any, <:Dict}, ValueIterator{<:Dict}}
i == 0 && return nothing
i = skip_deleted(v.dict, i)
i === nothing && return nothing # This is to catch nothing returned by skip_deleted
i == 0 && return nothing
vals = T <: KeySet ? v.dict.keys : v.dict.vals
(@inbounds vals[i], i == typemax(Int) ? nothing : i+1)
(@inbounds vals[i], i == typemax(Int) ? 0 : i+1)
end

filter!(f, d::Dict) = filter_in_one_pass!(f, d)
Expand Down

0 comments on commit 833269c

Please sign in to comment.