Remove pointer_{ref,mut} from tagged pointers

Just use `deref{,_mut}`!
This commit is contained in:
Maybe Waffle 2023-04-12 11:41:41 +00:00
parent c7c0b85f67
commit 8f408202c3
2 changed files with 11 additions and 20 deletions

View File

@ -115,19 +115,6 @@ pub fn pointer(self) -> P
unsafe { P::from_ptr(self.pointer_raw()) } unsafe { P::from_ptr(self.pointer_raw()) }
} }
pub fn pointer_ref(&self) -> &P::Target {
// SAFETY: pointer_raw returns the original pointer
unsafe { self.pointer_raw().as_ref() }
}
pub fn pointer_mut(&mut self) -> &mut P::Target
where
P: DerefMut,
{
// SAFETY: pointer_raw returns the original pointer
unsafe { self.pointer_raw().as_mut() }
}
#[inline] #[inline]
pub fn tag(&self) -> T { pub fn tag(&self) -> T {
unsafe { T::from_usize(self.packed.addr().get() >> Self::TAG_BIT_SHIFT) } unsafe { T::from_usize(self.packed.addr().get() >> Self::TAG_BIT_SHIFT) }
@ -147,7 +134,10 @@ impl<P, T, const COMPARE_PACKED: bool> Deref for CopyTaggedPtr<P, T, COMPARE_PAC
type Target = P::Target; type Target = P::Target;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
self.pointer_ref() // Safety:
// `pointer_raw` returns the original pointer from `P::into_ptr` which,
// by the `Pointer`'s contract, must be valid.
unsafe { self.pointer_raw().as_ref() }
} }
} }
@ -157,7 +147,11 @@ impl<P, T, const COMPARE_PACKED: bool> DerefMut for CopyTaggedPtr<P, T, COMPARE_
T: Tag, T: Tag,
{ {
fn deref_mut(&mut self) -> &mut Self::Target { fn deref_mut(&mut self) -> &mut Self::Target {
self.pointer_mut() // Safety:
// `pointer_raw` returns the original pointer from `P::into_ptr` which,
// by the `Pointer`'s contract, must be valid for writes if
// `P: DerefMut`.
unsafe { self.pointer_raw().as_mut() }
} }
} }

View File

@ -41,9 +41,6 @@ pub fn new(pointer: P, tag: T) -> Self {
TaggedPtr { raw: CopyTaggedPtr::new(pointer, tag) } TaggedPtr { raw: CopyTaggedPtr::new(pointer, tag) }
} }
pub fn pointer_ref(&self) -> &P::Target {
self.raw.pointer_ref()
}
pub fn tag(&self) -> T { pub fn tag(&self) -> T {
self.raw.tag() self.raw.tag()
} }
@ -56,7 +53,7 @@ impl<P, T, const COMPARE_PACKED: bool> std::ops::Deref for TaggedPtr<P, T, COMPA
{ {
type Target = P::Target; type Target = P::Target;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
self.raw.pointer_ref() self.raw.deref()
} }
} }
@ -66,7 +63,7 @@ impl<P, T, const COMPARE_PACKED: bool> std::ops::DerefMut for TaggedPtr<P, T, CO
T: Tag, T: Tag,
{ {
fn deref_mut(&mut self) -> &mut Self::Target { fn deref_mut(&mut self) -> &mut Self::Target {
self.raw.pointer_mut() self.raw.deref_mut()
} }
} }