Skip to content

Commit 97073fb

Browse files
committed
Fast-path contains() for empty Dictionaries
1 parent 63124b5 commit 97073fb

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

stdlib/public/core/NativeDictionary.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ extension _NativeDictionary: _DictionaryBuffer {
354354
@inlinable
355355
@inline(__always)
356356
func contains(_ key: Key) -> Bool {
357+
if count == 0 {
358+
// Fast path that avoids computing the hash of the key.
359+
return false
360+
}
357361
return find(key).found
358362
}
359363

0 commit comments

Comments
 (0)