-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Id::retain_autoreleased
#81
Conversation
6f90766
to
ae34940
Compare
ae34940
to
419086c
Compare
419086c
to
608d251
Compare
8f43ce3
to
5d1b3f9
Compare
Since if ptr != res {
unsafe { core::hint::unreachable_unchecked() };
} Conclusion: This was turned in to an |
b5297b9
to
908f914
Compare
I considered just changing |
An optimized version of `Id::retain` for when the previous caller returns an autoreleased value
908f914
to
597c950
Compare
597c950
to
e149351
Compare
Note: given that Cranelift doesn't support inline assembly, neither does A possibility would be to put the assembly stuff inside |
An optimized version of
Id::retain
that usesobjc_retainAutoreleasedReturnValue
for when the previous caller returns an autoreleased value withobjc_autoreleaseReturnValue
. This is a common thing in ARC code to avoid unnecessaryautorelease/retain
pairs, but it is (apart from changing the retain count) purely an optimization.This uses the newly stabilized inline assembly, which can easily cause very undefined behaviour if used incorrectly. Luckily, the instructions are exceedingly simple (essentially just a special
nop
), so there's almost no room for error - so fingers crossed I got this right (at least enough that it doesn't cause UB)!I've tested this on my local machine (both x86 and x86_64), and I've also added assembly tests to ensure that enough optimizations actually happen to make it work. At some point I would really like a helper like Apple's
TestRoot
instead of the brittle checking ofretainCount
that we do now, but I'll defer that to later.Related: gfx-rs/metal-rs#222