Skip to content

Commit 0a986b5

Browse files
authored
Merge pull request swiftlang#38638 from Catfish-Man/zero-is-the-loneliest-dictionary
Fast-path contains() for empty Dictionaries
2 parents 58804f7 + 97073fb commit 0a986b5

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)