Skip to content

Commit

Permalink
Fast retain. Refs #1
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Jun 17, 2023
1 parent 8c78b80 commit e351a62
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion cidre/src/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::objc;

#[cfg(feature = "objc")]
use std::{
arch::asm,
ops::{Deref, DerefMut},
ptr::NonNull,
};
Expand Down Expand Up @@ -177,6 +176,8 @@ pub type Rar<T> = ReturnedAutoReleased<T>;
#[cfg(feature = "objc")]
#[inline]
pub fn rar_retain_option<T: objc::Obj>(id: Option<Rar<T>>) -> Option<R<T>> {
use std::arch::asm;

unsafe {
// see comments in rar_retain
asm!("mov x29, x29");
Expand All @@ -189,6 +190,8 @@ pub fn rar_retain_option<T: objc::Obj>(id: Option<Rar<T>>) -> Option<R<T>> {
#[cfg(feature = "objc")]
#[inline]
pub fn rar_retain<T: objc::Obj>(id: Rar<T>) -> R<T> {
use std::arch::asm;

unsafe {
// latest runtimes don't need this marker anymore.
// see https://developer.apple.com/videos/play/wwdc2022/110363/ at 13:24
Expand Down
12 changes: 10 additions & 2 deletions cidre/src/objc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ impl<T: Obj> arc::Retain for T {
pub trait Obj: Sized + arc::Retain {
#[inline]
unsafe fn retain(id: &Self) -> arc::R<Self> {
transmute(objc_retain(transmute(id)))
let result: *mut Self;
core::arch::asm!(
"bl _objc_retain_{obj:x}",
obj = in(reg) id,
lateout("x0") result,
clobber_abi("C"),
);
transmute(result)
// transmute(objc_retain(transmute(id)))
}

#[msg_send(description)]
Expand Down Expand Up @@ -158,7 +166,7 @@ where

#[link(name = "objc", kind = "dylib")]
extern "C" {
fn objc_retain<'a>(obj: &Id) -> &'a Id;
// fn objc_retain<'a>(obj: &Id) -> &'a Id;
// fn objc_release(obj: &mut Id);

fn class_createInstance(cls: &Class<Id>, extra_bytes: usize) -> Option<arc::A<Id>>;
Expand Down

0 comments on commit e351a62

Please sign in to comment.