Skip to content

Commit

Permalink
return immediately from ht_keyindex if dictionary is empty (JuliaLa…
Browse files Browse the repository at this point in the history
…ng#44341)

Avoids hashing the input key for empty dictionaries.

Inspired by rust-lang/hashbrown#305.
  • Loading branch information
KristofferC authored and LilithHafner committed Mar 8, 2022
1 parent 451b7ad commit afeb2be
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ end

# get the index where a key is stored, or -1 if not present
function ht_keyindex(h::Dict{K,V}, key) where V where K
isempty(h) && return -1
sz = length(h.keys)
iter = 0
maxprobe = h.maxprobe
Expand Down

0 comments on commit afeb2be

Please sign in to comment.