| 
6 | 6 |     WeakKeyDict([itr])  | 
7 | 7 | 
  | 
8 | 8 | `WeakKeyDict()` constructs a hash table where the keys are weak  | 
9 |  | -references to objects, and thus may be garbage collected even when  | 
 | 9 | +references to objects which may be garbage collected even when  | 
10 | 10 | referenced in a hash table.  | 
11 | 11 | 
  | 
12 | 12 | See [`Dict`](@ref) for further help.  Note, unlike [`Dict`](@ref),  | 
@@ -111,24 +111,12 @@ getindex(wkh::WeakKeyDict{K}, key) where {K} = lock(() -> getindex(wkh.ht, key),  | 
111 | 111 | isempty(wkh::WeakKeyDict) = isempty(wkh.ht)  | 
112 | 112 | length(t::WeakKeyDict) = length(t.ht)  | 
113 | 113 | 
 
  | 
114 |  | -function iterate(t::WeakKeyDict{K,V}) where V where K  | 
115 |  | -    gc_token = Ref{Bool}(false) # no keys will be deleted via finalizers until this token is gc'd  | 
116 |  | -    finalizer(gc_token) do r  | 
117 |  | -        if r[]  | 
118 |  | -            r[] = false  | 
119 |  | -            unlock(t.lock)  | 
120 |  | -        end  | 
121 |  | -    end  | 
122 |  | -    s = lock(t.lock)  | 
123 |  | -    iterate(t, (gc_token,))  | 
124 |  | -end  | 
125 |  | -function iterate(t::WeakKeyDict{K,V}, state) where V where K  | 
126 |  | -    gc_token = first(state)  | 
127 |  | -    y = iterate(t.ht, tail(state)...)  | 
 | 114 | +function iterate(t::WeakKeyDict{K,V}, state...) where {K, V}  | 
 | 115 | +    y = lock(() -> iterate(t.ht, state...), t)  | 
128 | 116 |     y === nothing && return nothing  | 
129 |  | -    wkv, i = y  | 
 | 117 | +    wkv, newstate = y  | 
130 | 118 |     kv = Pair{K,V}(wkv[1].value::K, wkv[2])  | 
131 |  | -    return (kv, (gc_token, i))  | 
 | 119 | +    return (kv, newstate)  | 
132 | 120 | end  | 
133 | 121 | 
 
  | 
134 | 122 | filter!(f, d::WeakKeyDict) = filter_in_one_pass!(f, d)  | 
0 commit comments