@@ -2139,28 +2139,32 @@ final internal class _HashableTypedNativeDictionaryStorage<Key: Hashable, Value>
2139
2139
andKeys keys: UnsafeMutablePointer < AnyObject > ? ,
2140
2140
count: Int ) {
2141
2141
_precondition ( count >= 0 , " Invalid count " )
2142
- // The user is expected to provide a storage of the correct size
2142
+ guard count > 0 else { return }
2143
+ var i = 0 // Current position in the output buffers
2143
2144
if let unmanagedKeys = _UnmanagedAnyObjectArray ( keys) {
2144
2145
if let unmanagedObjects = _UnmanagedAnyObjectArray ( objects) {
2145
2146
// keys nonnull, objects nonnull
2146
- for (offset: i, element: ( key: key, value: val) ) in full. enumerated ( ) {
2147
- guard i < count else { break }
2148
- unmanagedObjects [ i] = _bridgeAnythingToObjectiveC ( val)
2147
+ for (key, value) in full {
2148
+ unmanagedObjects [ i] = _bridgeAnythingToObjectiveC ( value)
2149
2149
unmanagedKeys [ i] = _bridgeAnythingToObjectiveC ( key)
2150
+ i += 1
2151
+ guard i < count else { break }
2150
2152
}
2151
2153
} else {
2152
2154
// keys nonnull, objects null
2153
- for (offset: i, element: ( key: key, value: _) ) in full. enumerated ( ) {
2154
- guard i < count else { break }
2155
+ for (key, _) in full {
2155
2156
unmanagedKeys [ i] = _bridgeAnythingToObjectiveC ( key)
2157
+ i += 1
2158
+ guard i < count else { break }
2156
2159
}
2157
2160
}
2158
2161
} else {
2159
2162
if let unmanagedObjects = _UnmanagedAnyObjectArray ( objects) {
2160
2163
// keys null, objects nonnull
2161
- for (offset: i, element: ( key: _, value: val) ) in full. enumerated ( ) {
2164
+ for (_, value) in full {
2165
+ unmanagedObjects [ i] = _bridgeAnythingToObjectiveC ( value)
2166
+ i += 1
2162
2167
guard i < count else { break }
2163
- unmanagedObjects [ i] = _bridgeAnythingToObjectiveC ( val)
2164
2168
}
2165
2169
} else {
2166
2170
// do nothing, both are null
@@ -2944,29 +2948,29 @@ final internal class _SwiftDeferredNSDictionary<Key: Hashable, Value>
2944
2948
_ count: Int
2945
2949
) {
2946
2950
_precondition ( count >= 0 , " Invalid count " )
2951
+ guard count > 0 else { return }
2947
2952
bridgeEverything ( )
2948
- // The user is expected to provide a storage of the correct size
2949
- var i = 0 // Position in the input storage
2953
+ var i = 0 // Current position in the output buffers
2950
2954
let bucketCount = nativeBuffer. bucketCount
2951
2955
2952
2956
if let unmanagedKeys = _UnmanagedAnyObjectArray ( keys) {
2953
2957
if let unmanagedObjects = _UnmanagedAnyObjectArray ( objects) {
2954
2958
// keys nonnull, objects nonnull
2955
2959
for position in 0 ..< bucketCount {
2956
2960
if bridgedBuffer. isInitializedEntry ( at: position) {
2957
- guard i < count else { break }
2958
2961
unmanagedObjects [ i] = bridgedBuffer. value ( at: position)
2959
2962
unmanagedKeys [ i] = bridgedBuffer. key ( at: position)
2960
2963
i += 1
2964
+ guard i < count else { break }
2961
2965
}
2962
2966
}
2963
2967
} else {
2964
2968
// keys nonnull, objects null
2965
2969
for position in 0 ..< bucketCount {
2966
2970
if bridgedBuffer. isInitializedEntry ( at: position) {
2967
- guard i < count else { break }
2968
2971
unmanagedKeys [ i] = bridgedBuffer. key ( at: position)
2969
2972
i += 1
2973
+ guard i < count else { break }
2970
2974
}
2971
2975
}
2972
2976
}
@@ -2975,9 +2979,9 @@ final internal class _SwiftDeferredNSDictionary<Key: Hashable, Value>
2975
2979
// keys null, objects nonnull
2976
2980
for position in 0 ..< bucketCount {
2977
2981
if bridgedBuffer. isInitializedEntry ( at: position) {
2978
- guard i < count else { break }
2979
2982
unmanagedObjects [ i] = bridgedBuffer. value ( at: position)
2980
2983
i += 1
2984
+ guard i < count else { break }
2981
2985
}
2982
2986
}
2983
2987
} else {
0 commit comments