Skip to content

Commit 7826c3c

Browse files
committed
[stdlib] Dictionary.mapValues: Copy the seed over to the new dictionary
1 parent 91c5a31 commit 7826c3c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

stdlib/public/core/NativeDictionary.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,13 @@ extension _NativeDictionary { // High-level operations
571571
internal func mapValues<T>(
572572
_ transform: (Value) throws -> T
573573
) rethrows -> _NativeDictionary<Key, T> {
574-
let result = _NativeDictionary<Key, T>(capacity: capacity)
575-
// Because the keys in the current and new buffer are the same, we can
574+
let (resultStorage, rehash) = _DictionaryStorage<Key, T>.reallocate(
575+
original: _storage,
576+
capacity: capacity)
577+
_sanityCheck(!rehash)
578+
_sanityCheck(resultStorage._seed == _storage._seed)
579+
let result = _NativeDictionary<Key, T>(resultStorage)
580+
// Because the current and new buffer have the same scale and seed, we can
576581
// initialize to the same locations in the new buffer, skipping hash value
577582
// recalculations.
578583
for bucket in hashTable {

0 commit comments

Comments
 (0)