Skip to content

Commit 548f59a

Browse files
committed
[stdlib] Set, Dictionary: Make internal representations conform to Sequence
1 parent 5e969ce commit 548f59a

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

stdlib/public/core/Dictionary.swift

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,10 +2080,6 @@ final internal class _HashableTypedNativeDictionaryStorage<Key: Hashable, Value>
20802080
return _NativeDictionary(_storage: self)
20812081
}
20822082

2083-
internal var full: Dictionary<Key, Value> {
2084-
return Dictionary(_native: native)
2085-
}
2086-
20872083
@objc
20882084
internal override func enumerator() -> _NSEnumerator {
20892085
return _SwiftDictionaryNSEnumerator<Key, Value>(
@@ -2169,15 +2165,15 @@ final internal class _HashableTypedNativeDictionaryStorage<Key: Hashable, Value>
21692165
if let unmanagedKeys = _UnmanagedAnyObjectArray(keys) {
21702166
if let unmanagedObjects = _UnmanagedAnyObjectArray(objects) {
21712167
// keys nonnull, objects nonnull
2172-
for (key, value) in full {
2168+
for (key, value) in native {
21732169
unmanagedObjects[i] = _bridgeAnythingToObjectiveC(value)
21742170
unmanagedKeys[i] = _bridgeAnythingToObjectiveC(key)
21752171
i += 1
21762172
guard i < count else { break }
21772173
}
21782174
} else {
21792175
// keys nonnull, objects null
2180-
for (key, _) in full {
2176+
for (key, _) in native {
21812177
unmanagedKeys[i] = _bridgeAnythingToObjectiveC(key)
21822178
i += 1
21832179
guard i < count else { break }
@@ -2186,7 +2182,7 @@ final internal class _HashableTypedNativeDictionaryStorage<Key: Hashable, Value>
21862182
} else {
21872183
if let unmanagedObjects = _UnmanagedAnyObjectArray(objects) {
21882184
// keys null, objects nonnull
2189-
for (_, value) in full {
2185+
for (_, value) in native {
21902186
unmanagedObjects[i] = _bridgeAnythingToObjectiveC(value)
21912187
i += 1
21922188
guard i < count else { break }
@@ -2589,8 +2585,9 @@ extension _NativeDictionary where Key: Hashable {
25892585
maxLoadFactorInverse: Double
25902586
) -> Int {
25912587
// `capacity + 1` below ensures that we don't fill in the last hole
2592-
return max(Int((Double(capacity) * maxLoadFactorInverse).rounded(.up)),
2593-
capacity + 1)
2588+
return Swift.max(
2589+
Int((Double(capacity) * maxLoadFactorInverse).rounded(.up)),
2590+
capacity + 1)
25942591
}
25952592

25962593
/// Self should be uniquely referenced.
@@ -4224,7 +4221,7 @@ extension Dictionary.Index: Hashable {
42244221
}
42254222
}
42264223

4227-
extension _NativeDictionary {
4224+
extension _NativeDictionary: Sequence {
42284225
@usableFromInline
42294226
@_fixed_layout
42304227
internal struct Iterator {
@@ -4269,7 +4266,7 @@ extension _NativeDictionary.Iterator: IteratorProtocol {
42694266
}
42704267

42714268
#if _runtime(_ObjC)
4272-
extension _CocoaDictionary {
4269+
extension _CocoaDictionary: Sequence {
42734270
@usableFromInline
42744271
final internal class Iterator {
42754272
// Cocoa Dictionary iterator has to be a class, otherwise we cannot

stdlib/public/core/Set.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,8 +2106,9 @@ extension _NativeSet/*: _SetBuffer*/ where Element: Hashable {
21062106
maxLoadFactorInverse: Double
21072107
) -> Int {
21082108
// `capacity + 1` below ensures that we don't fill in the last hole
2109-
return max(Int((Double(capacity) * maxLoadFactorInverse).rounded(.up)),
2110-
capacity + 1)
2109+
return Swift.max(
2110+
Int((Double(capacity) * maxLoadFactorInverse).rounded(.up)),
2111+
capacity + 1)
21112112
}
21122113

21132114
/// Buffer should be uniquely referenced.
@@ -3421,7 +3422,7 @@ extension Set.Index: Hashable {
34213422
}
34223423
}
34233424

3424-
extension _NativeSet {
3425+
extension _NativeSet: Sequence {
34253426
@usableFromInline
34263427
@_fixed_layout
34273428
internal struct Iterator {
@@ -3463,7 +3464,7 @@ extension _NativeSet.Iterator: IteratorProtocol {
34633464
}
34643465

34653466
#if _runtime(_ObjC)
3466-
extension _CocoaSet {
3467+
extension _CocoaSet: Sequence {
34673468
@usableFromInline
34683469
final internal class Iterator {
34693470
// Cocoa Set iterator has to be a class, otherwise we cannot

0 commit comments

Comments
 (0)