Skip to content

Commit b697c70

Browse files
committed
Switched AnyHashable _bridgeToObjectiveC to use __SwiftValue.store instead
1 parent fc02612 commit b697c70

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

Diff for: Sources/Foundation/Bridging.swift

+6-8
Original file line numberDiff line numberDiff line change
@@ -230,25 +230,23 @@ internal final class __SwiftValue : NSObject, NSCopying {
230230
// MARK: AnyHashable Bridging
231231
extension AnyHashable : _ObjectiveCBridgeable {
232232
public func _bridgeToObjectiveC() -> NSObject {
233-
// This is unprincipled, but pretty much any object we'll encounter in
234-
// Swift is NSObject-conforming enough to have -hash and -isEqual:.
235-
return unsafeBitCast(base as AnyObject, to: NSObject.self)
233+
return __SwiftValue.store(base)
236234
}
237-
235+
238236
public static func _forceBridgeFromObjectiveC(_ x: NSObject, result: inout AnyHashable?) {
239-
result = AnyHashable(x)
237+
result = (__SwiftValue.fetch(x) as? AnyHashable) ?? AnyHashable(x)
240238
}
241-
239+
242240
public static func _conditionallyBridgeFromObjectiveC(_ x: NSObject, result: inout AnyHashable?) -> Bool {
243241
self._forceBridgeFromObjectiveC(x, result: &result)
244242
return result != nil
245243
}
246-
244+
247245
@_effects(readonly)
248246
public static func _unconditionallyBridgeFromObjectiveC(_ source: NSObject?) -> AnyHashable {
249247
// `nil` has historically been used as a stand-in for an empty
250248
// string; map it to an empty string.
251249
if _slowPath(source == nil) { return AnyHashable(String()) }
252-
return AnyHashable(source!)
250+
return (__SwiftValue.fetch(source) as? AnyHashable) ?? AnyHashable(source!)
253251
}
254252
}

Diff for: Sources/Foundation/Morphology.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ extension Morphology {
342342

343343
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
344344
extension NSAttributedString.Key {
345-
internal static var morphology = NSAttributedString.Key(rawValue: "NSMorphology")
346-
internal static var inflectionRule = NSAttributedString.Key(rawValue: "NSInflect")
347-
internal static var inflectionAlternative = NSAttributedString.Key(rawValue: "NSInflectionAlternative")
348-
internal static var language = NSAttributedString.Key(rawValue: "NSLanguage")
345+
public static let morphology = NSAttributedString.Key(rawValue: "NSMorphology")
346+
public static let inflectionRule = NSAttributedString.Key(rawValue: "NSInflect")
347+
public static let inflectionAlternative = NSAttributedString.Key(rawValue: "NSInflectionAlternative")
348+
public static let language = NSAttributedString.Key(rawValue: "NSLanguage")
349349
}

0 commit comments

Comments
 (0)