Skip to content

Commit 17f2bda

Browse files
Merge pull request #24647 from Catfish-Man/pointernt-5.1
[5.1] Use the Swift runtime's (faster) class check in the stdlib instead of shimming object_getClass()
2 parents c98e292 + 32e0d4e commit 17f2bda

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

stdlib/public/core/Builtin.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@ func _uncheckedUnsafeAssume(_ condition: Bool) {
318318
@usableFromInline
319319
@_silgen_name("_swift_objcClassUsesNativeSwiftReferenceCounting")
320320
internal func _usesNativeSwiftReferenceCounting(_ theClass: AnyClass) -> Bool
321+
322+
/// Returns the class of a non-tagged-pointer Objective-C object
323+
@_effects(readonly)
324+
@_silgen_name("_swift_classOfObjCHeapObject")
325+
internal func _swift_classOfObjCHeapObject(_ object: AnyObject) -> AnyClass
321326
#else
322327
@inlinable
323328
@inline(__always)

stdlib/public/core/StringBridge.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,6 @@ private var kCFStringEncodingUTF8 : _swift_shims_CFStringEncoding {
125125
@inline(__always) get { return 0x8000100 }
126126
}
127127

128-
@_effects(readonly)
129-
private func _unsafeAddressOfCocoaStringClass(_ str: _CocoaString) -> UInt {
130-
return _swift_stdlib_unsafeAddressOfClass(str)
131-
}
132-
133128
internal enum _KnownCocoaString {
134129
case storage
135130
case shared
@@ -148,7 +143,7 @@ internal enum _KnownCocoaString {
148143
}
149144
#endif
150145

151-
switch _unsafeAddressOfCocoaStringClass(str) {
146+
switch unsafeBitCast(_swift_classOfObjCHeapObject(str), to: UInt.self) {
152147
case unsafeBitCast(__StringStorage.self, to: UInt.self):
153148
self = .storage
154149
case unsafeBitCast(__SharedStringStorage.self, to: UInt.self):

stdlib/public/runtime/SwiftObject.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ static Class _swift_getObjCClassOfAllocated(const void *object) {
177177
class_getInstanceSize(cls), mask));
178178
}
179179

180+
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_API
181+
Class _swift_classOfObjCHeapObject(OpaqueValue *value) {
182+
return _swift_getObjCClassOfAllocated(value);
183+
}
184+
180185
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_API
181186
NSString *swift_stdlib_getDescription(OpaqueValue *value,
182187
const Metadata *type);

0 commit comments

Comments
 (0)