Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions stdlib/public/core/DictionaryStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,35 @@ extension __RawDictionaryStorage {
return Builtin.bridgeFromRawPointer(
Builtin.addressof(&_swiftEmptyDictionarySingleton))
}

@_alwaysEmitIntoClient
@inline(__always)
internal final func uncheckedKey<Key: Hashable>(at bucket: _HashTable.Bucket) -> Key {
defer { _fixLifetime(self) }
_internalInvariant(_hashTable.isOccupied(bucket))
let keys = _rawKeys.assumingMemoryBound(to: Key.self)
return keys[bucket.offset]
}

@_alwaysEmitIntoClient
@inline(never)
internal final func find<Key: Hashable>(_ key: Key) -> (bucket: _HashTable.Bucket, found: Bool) {
return find(key, hashValue: key._rawHashValue(seed: _seed))
}

@_alwaysEmitIntoClient
@inline(never)
internal final func find<Key: Hashable>(_ key: Key, hashValue: Int) -> (bucket: _HashTable.Bucket, found: Bool) {
let hashTable = _hashTable
var bucket = hashTable.idealBucket(forHashValue: hashValue)
while hashTable._isOccupied(bucket) {
if uncheckedKey(at: bucket) == key {
return (bucket, true)
}
bucket = hashTable.bucket(wrappedAfter: bucket)
}
return (bucket, false)
}
}

@usableFromInline
Expand Down
12 changes: 2 additions & 10 deletions stdlib/public/core/NativeDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ extension _NativeDictionary { // Low-level lookup operations
@inlinable
@inline(__always)
internal func find(_ key: Key) -> (bucket: Bucket, found: Bool) {
return find(key, hashValue: self.hashValue(for: key))
return _storage.find(key)
}

/// Search for a given element, assuming it has the specified hash value.
Expand All @@ -174,15 +174,7 @@ extension _NativeDictionary { // Low-level lookup operations
_ key: Key,
hashValue: Int
) -> (bucket: Bucket, found: Bool) {
let hashTable = self.hashTable
var bucket = hashTable.idealBucket(forHashValue: hashValue)
while hashTable._isOccupied(bucket) {
if uncheckedKey(at: bucket) == key {
return (bucket, true)
}
bucket = hashTable.bucket(wrappedAfter: bucket)
}
return (bucket, false)
return _storage.find(key, hashValue: hashValue)
}
}

Expand Down