@@ -398,8 +398,10 @@ public struct Set<Element : Hashable> :
398
398
_sanityCheck(_isBridgedVerbatimToObjectiveC(Element.self),
399
399
"Set can be backed by NSSet _variantBuffer only when the member type can be bridged verbatim to Objective-C")
400
400
401
- // TODO: rewrite this
402
- self.init()
401
+ _buffer = _NativeBuffer(minimumCapacity: _immutableCocoaSet.count)
402
+ _immutableCocoaSet.enumerateObjectsUsingBlock { (key, stop) in
403
+ insert(_forceBridgeFromObjectiveC(key, Element.self))
404
+ }
403
405
}
404
406
#endif
405
407
@@ -1204,19 +1206,12 @@ public func _setDownCastIndirect<SourceValue, TargetValue>(
1204
1206
/// are reference types.
1205
1207
public func _setDownCast<BaseValue, DerivedValue>(_ source: Set<BaseValue>)
1206
1208
-> Set<DerivedValue> {
1207
- /* TODO: check out what this did
1208
1209
#if _runtime(_ObjC)
1209
1210
if _isClassOrObjCExistential(BaseValue.self)
1210
1211
&& _isClassOrObjCExistential(DerivedValue.self) {
1211
- switch source._variantBuffer {
1212
- case _VariantSetBuffer.native(let buffer):
1213
- return Set(_immutableCocoaSet: buffer.bridged())
1214
- case _VariantSetBuffer.cocoa(let cocoaBuffer):
1215
- return Set(_immutableCocoaSet: cocoaBuffer.cocoaSet)
1216
- }
1212
+ return Set(_immutableCocoaSet: source._bridgeToObjectiveCImpl())
1217
1213
}
1218
1214
#endif
1219
- */
1220
1215
return _setDownCastConditional(source)!
1221
1216
}
1222
1217
@@ -1537,15 +1532,18 @@ public struct Dictionary<Key : Hashable, Value> :
1537
1532
/// * `Key` and `Value` are bridged verbatim to Objective-C (i.e.,
1538
1533
/// are reference types).
1539
1534
public init(_immutableCocoaDictionary: _NSDictionary) {
1540
- /* TODO: replace this
1541
1535
_sanityCheck(
1542
1536
_isBridgedVerbatimToObjectiveC(Key.self) &&
1543
1537
_isBridgedVerbatimToObjectiveC(Value.self),
1544
1538
"Dictionary can be backed by NSDictionary buffer only when both key and value are bridged verbatim to Objective-C")
1545
- _buffer = .cocoa(
1546
- _CocoaDictionaryBuffer(cocoaDictionary: _immutableCocoaDictionary))
1547
- */
1548
- self.init()
1539
+
1540
+ _buffer = _NativeBuffer(minimumCapacity: _immutableCocoaDictionary.count)
1541
+ _immutableCocoaDictionary.enumerateKeysAndObjectsUsingBlock {
1542
+ (key, value, stop) in
1543
+ let _ = _buffer.insert(
1544
+ _forceBridgeFromObjectiveC(value, Value.self),
1545
+ forKey: _forceBridgeFromObjectiveC(key, Key.self))
1546
+ }
1549
1547
}
1550
1548
#endif
1551
1549
@@ -2106,24 +2104,17 @@ public func _dictionaryDownCast<BaseKey, BaseValue, DerivedKey, DerivedValue>(
2106
2104
_ source: Dictionary<BaseKey, BaseValue>
2107
2105
) -> Dictionary<DerivedKey, DerivedValue> {
2108
2106
2109
- /* TODO: figure out what this did
2110
2107
#if _runtime(_ObjC)
2111
2108
if _isClassOrObjCExistential(BaseKey.self)
2112
2109
&& _isClassOrObjCExistential(BaseValue.self)
2113
2110
&& _isClassOrObjCExistential(DerivedKey.self)
2114
2111
&& _isClassOrObjCExistential(DerivedValue.self) {
2115
-
2116
- switch source._variantBuffer {
2117
- case .native(let buffer):
2118
- // Note: it is safe to treat the buffer as immutable here because
2119
- // Dictionary will not mutate buffer with reference count greater than 1.
2120
- return Dictionary(_immutableCocoaDictionary: buffer.bridged())
2121
- case .cocoa(let cocoaBuffer):
2122
- return Dictionary(_immutableCocoaDictionary: cocoaBuffer.cocoaDictionary)
2123
- }
2112
+ // Note: it is safe to treat the buffer as immutable here because
2113
+ // Dictionary will not mutate buffer with reference count greater than 1.
2114
+ return Dictionary(
2115
+ _immutableCocoaDictionary: source._bridgeToObjectiveCImpl())
2124
2116
}
2125
2117
#endif
2126
- */
2127
2118
return _dictionaryDownCastConditional(source)!
2128
2119
}
2129
2120
@@ -4031,7 +4022,7 @@ extension ${Self} {
4031
4022
4032
4023
#if _runtime(_ObjC)
4033
4024
extension ${Self} {
4034
- public func _bridgeToObjectiveCImpl() -> _NS${Self}Core {
4025
+ public func _bridgeToObjectiveCImpl() -> _NS${Self} {
4035
4026
return _buffer.bridged()
4036
4027
}
4037
4028
0 commit comments