@@ -2177,28 +2177,32 @@ final internal class _HashableTypedNativeDictionaryStorage<Key: Hashable, Value>
2177
2177
andKeys keys: UnsafeMutablePointer < AnyObject > ? ,
2178
2178
count: Int ) {
2179
2179
_precondition ( count >= 0 , " Invalid count " )
2180
- // The user is expected to provide a storage of the correct size
2180
+ guard count > 0 else { return }
2181
+ var i = 0 // Current position in the output buffers
2181
2182
if let unmanagedKeys = _UnmanagedAnyObjectArray ( keys) {
2182
2183
if let unmanagedObjects = _UnmanagedAnyObjectArray ( objects) {
2183
2184
// keys nonnull, objects nonnull
2184
- for (offset: i, element: ( key: key, value: val) ) in full. enumerated ( ) {
2185
- guard i < count else { break }
2186
- unmanagedObjects [ i] = _bridgeAnythingToObjectiveC ( val)
2185
+ for (key, value) in full {
2186
+ unmanagedObjects [ i] = _bridgeAnythingToObjectiveC ( value)
2187
2187
unmanagedKeys [ i] = _bridgeAnythingToObjectiveC ( key)
2188
+ i += 1
2189
+ guard i < count else { break }
2188
2190
}
2189
2191
} else {
2190
2192
// keys nonnull, objects null
2191
- for (offset: i, element: ( key: key, value: _) ) in full. enumerated ( ) {
2192
- guard i < count else { break }
2193
+ for (key, _) in full {
2193
2194
unmanagedKeys [ i] = _bridgeAnythingToObjectiveC ( key)
2195
+ i += 1
2196
+ guard i < count else { break }
2194
2197
}
2195
2198
}
2196
2199
} else {
2197
2200
if let unmanagedObjects = _UnmanagedAnyObjectArray ( objects) {
2198
2201
// keys null, objects nonnull
2199
- for (offset: i, element: ( key: _, value: val) ) in full. enumerated ( ) {
2202
+ for (_, value) in full {
2203
+ unmanagedObjects [ i] = _bridgeAnythingToObjectiveC ( value)
2204
+ i += 1
2200
2205
guard i < count else { break }
2201
- unmanagedObjects [ i] = _bridgeAnythingToObjectiveC ( val)
2202
2206
}
2203
2207
} else {
2204
2208
// do nothing, both are null
@@ -2971,29 +2975,29 @@ final internal class _SwiftDeferredNSDictionary<Key: Hashable, Value>
2971
2975
_ count: Int
2972
2976
) {
2973
2977
_precondition ( count >= 0 , " Invalid count " )
2978
+ guard count > 0 else { return }
2974
2979
bridgeEverything ( )
2975
- // The user is expected to provide a storage of the correct size
2976
- var i = 0 // Position in the input storage
2980
+ var i = 0 // Current position in the output buffers
2977
2981
let bucketCount = nativeBuffer. bucketCount
2978
2982
2979
2983
if let unmanagedKeys = _UnmanagedAnyObjectArray ( keys) {
2980
2984
if let unmanagedObjects = _UnmanagedAnyObjectArray ( objects) {
2981
2985
// keys nonnull, objects nonnull
2982
2986
for position in 0 ..< bucketCount {
2983
2987
if bridgedBuffer. isInitializedEntry ( at: position) {
2984
- guard i < count else { break }
2985
2988
unmanagedObjects [ i] = bridgedBuffer. value ( at: position)
2986
2989
unmanagedKeys [ i] = bridgedBuffer. key ( at: position)
2987
2990
i += 1
2991
+ guard i < count else { break }
2988
2992
}
2989
2993
}
2990
2994
} else {
2991
2995
// keys nonnull, objects null
2992
2996
for position in 0 ..< bucketCount {
2993
2997
if bridgedBuffer. isInitializedEntry ( at: position) {
2994
- guard i < count else { break }
2995
2998
unmanagedKeys [ i] = bridgedBuffer. key ( at: position)
2996
2999
i += 1
3000
+ guard i < count else { break }
2997
3001
}
2998
3002
}
2999
3003
}
@@ -3002,9 +3006,9 @@ final internal class _SwiftDeferredNSDictionary<Key: Hashable, Value>
3002
3006
// keys null, objects nonnull
3003
3007
for position in 0 ..< bucketCount {
3004
3008
if bridgedBuffer. isInitializedEntry ( at: position) {
3005
- guard i < count else { break }
3006
3009
unmanagedObjects [ i] = bridgedBuffer. value ( at: position)
3007
3010
i += 1
3011
+ guard i < count else { break }
3008
3012
}
3009
3013
}
3010
3014
} else {
0 commit comments