inline go brrr

This commit is contained in:
Intege-rs
2024-11-16 20:46:53 -05:00
parent 5bdf077475
commit e20c5e251e

View File

@@ -31,17 +31,19 @@ unsafe impl<T> Sync for Mut<T> {}
unsafe impl<T> Send for Mut<T> {} unsafe impl<T> Send for Mut<T> {}
impl<T: Sized> Mut<T> { impl<T: Sized> Mut<T> {
#[inline(always)]#[inline(always)]
pub const fn new(value: T) -> Self { pub const fn new(value: T) -> Self {
Self(core::cell::UnsafeCell::new(value)) Self(core::cell::UnsafeCell::new(value))
} }
#[inline(always)]
pub const fn as_ptr(&self) -> *mut T { pub const fn as_ptr(&self) -> *mut T {
self.0.get() self.0.get()
} }
} }
impl<T: Pod> Mut<T> { impl<T: Pod> Mut<T> {
pub fn set(&self, value: T) { unsafe { core::ptr::write(self.as_ptr(), value) } } #[inline(always)] pub fn set(&self, value: T) { unsafe { core::ptr::write(self.as_ptr(), value) } }
pub fn get(&self) -> T { unsafe { core::ptr::read(self.as_ptr()) } } #[inline(always)] pub fn get(&self) -> T { unsafe { core::ptr::read(self.as_ptr()) } }
} }
impl<T> Mut<MaybeUninit<T>> { impl<T> Mut<MaybeUninit<T>> {
pub const fn zeroed() -> Self { Self(core::cell::UnsafeCell::new(MaybeUninit::zeroed())) } pub const fn zeroed() -> Self { Self(core::cell::UnsafeCell::new(MaybeUninit::zeroed())) }
@@ -50,5 +52,8 @@ impl<T> Mut<MaybeUninit<T>> {
impl<T> Deref for Mut<T> { impl<T> Deref for Mut<T> {
type Target = core::cell::UnsafeCell<T>; type Target = core::cell::UnsafeCell<T>;
fn deref(&self) -> &Self::Target { &self.0 } #[inline(always)]
fn deref(&self) -> &Self::Target {
&self.0
}
} }