Skip to content

Commit 90cfaa1

Browse files
committed
[Runtime] Tail call swift_retain in ObjC retain implementation.
The implementation of the ObjC -retain method saved a local variable and returned that after calling swift_retain, which forced it to create a stack frame. swift_retain returns the object being retained, so we can take advantage of that to have the compiler emit a tail call to it instead.
1 parent a4bfa3f commit 90cfaa1

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

include/swift/Runtime/HeapObject.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,8 +1159,7 @@ swift_getMangledTypeName(const Metadata *type);
11591159
#define STANDARD_OBJC_METHOD_IMPLS_FOR_SWIFT_OBJECTS \
11601160
- (id)retain { \
11611161
auto SELF = reinterpret_cast<HeapObject *>(self); \
1162-
swift_retain(SELF); \
1163-
return self; \
1162+
return reinterpret_cast<id>(swift_retain(SELF)); \
11641163
} \
11651164
- (oneway void)release { \
11661165
auto SELF = reinterpret_cast<HeapObject *>(self); \

0 commit comments

Comments
 (0)