Skip to content

Commit a2e4226

Browse files
authored
return immediately from ht_keyindex if dictionary is empty (#44341)
Avoids hashing the input key for empty dictionaries. Inspired by rust-lang/hashbrown#305.
1 parent 2e2c16a commit a2e4226

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

base/dict.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ end
278278

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

0 commit comments

Comments
 (0)