Sprinkle some #[inline]
in rustc_data_structures::tagged_ptr
This commit is contained in:
parent
91b61a4ad6
commit
021a12c00d
@ -82,11 +82,13 @@ impl<P, T, const CP: bool> CopyTaggedPtr<P, T, CP>
|
|||||||
/// drop, use [`TaggedPtr`] instead.
|
/// drop, use [`TaggedPtr`] instead.
|
||||||
///
|
///
|
||||||
/// [`TaggedPtr`]: crate::tagged_ptr::TaggedPtr
|
/// [`TaggedPtr`]: crate::tagged_ptr::TaggedPtr
|
||||||
|
#[inline]
|
||||||
pub fn new(pointer: P, tag: T) -> Self {
|
pub fn new(pointer: P, tag: T) -> Self {
|
||||||
Self { packed: Self::pack(P::into_ptr(pointer), tag), tag_ghost: PhantomData }
|
Self { packed: Self::pack(P::into_ptr(pointer), tag), tag_ghost: PhantomData }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves the pointer.
|
/// Retrieves the pointer.
|
||||||
|
#[inline]
|
||||||
pub fn pointer(self) -> P
|
pub fn pointer(self) -> P
|
||||||
where
|
where
|
||||||
P: Copy,
|
P: Copy,
|
||||||
@ -123,6 +125,7 @@ pub fn set_tag(&mut self, tag: T) {
|
|||||||
/// according to `self.packed` encoding scheme.
|
/// according to `self.packed` encoding scheme.
|
||||||
///
|
///
|
||||||
/// [`P::into_ptr`]: Pointer::into_ptr
|
/// [`P::into_ptr`]: Pointer::into_ptr
|
||||||
|
#[inline]
|
||||||
fn pack(ptr: NonNull<P::Target>, tag: T) -> NonNull<P::Target> {
|
fn pack(ptr: NonNull<P::Target>, tag: T) -> NonNull<P::Target> {
|
||||||
// Trigger assert!
|
// Trigger assert!
|
||||||
let () = Self::ASSERTION;
|
let () = Self::ASSERTION;
|
||||||
@ -145,6 +148,7 @@ fn pack(ptr: NonNull<P::Target>, tag: T) -> NonNull<P::Target> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves the original raw pointer from `self.packed`.
|
/// Retrieves the original raw pointer from `self.packed`.
|
||||||
|
#[inline]
|
||||||
pub(super) fn pointer_raw(&self) -> NonNull<P::Target> {
|
pub(super) fn pointer_raw(&self) -> NonNull<P::Target> {
|
||||||
self.packed.map_addr(|addr| unsafe { NonZeroUsize::new_unchecked(addr.get() << T::BITS) })
|
self.packed.map_addr(|addr| unsafe { NonZeroUsize::new_unchecked(addr.get() << T::BITS) })
|
||||||
}
|
}
|
||||||
@ -184,6 +188,7 @@ impl<P, T, const CP: bool> Clone for CopyTaggedPtr<P, T, CP>
|
|||||||
P: Pointer + Copy,
|
P: Pointer + Copy,
|
||||||
T: Tag,
|
T: Tag,
|
||||||
{
|
{
|
||||||
|
#[inline]
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
*self
|
*self
|
||||||
}
|
}
|
||||||
@ -196,6 +201,7 @@ impl<P, T, const CP: bool> Deref for CopyTaggedPtr<P, T, CP>
|
|||||||
{
|
{
|
||||||
type Target = P::Target;
|
type Target = P::Target;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
// Safety:
|
// Safety:
|
||||||
// `pointer_raw` returns the original pointer from `P::into_ptr` which,
|
// `pointer_raw` returns the original pointer from `P::into_ptr` which,
|
||||||
@ -209,6 +215,7 @@ impl<P, T, const CP: bool> DerefMut for CopyTaggedPtr<P, T, CP>
|
|||||||
P: Pointer + DerefMut,
|
P: Pointer + DerefMut,
|
||||||
T: Tag,
|
T: Tag,
|
||||||
{
|
{
|
||||||
|
#[inline]
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
// Safety:
|
// Safety:
|
||||||
// `pointer_raw` returns the original pointer from `P::into_ptr` which,
|
// `pointer_raw` returns the original pointer from `P::into_ptr` which,
|
||||||
@ -235,6 +242,7 @@ impl<P, T> PartialEq for CopyTaggedPtr<P, T, true>
|
|||||||
P: Pointer,
|
P: Pointer,
|
||||||
T: Tag,
|
T: Tag,
|
||||||
{
|
{
|
||||||
|
#[inline]
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.packed == other.packed
|
self.packed == other.packed
|
||||||
}
|
}
|
||||||
@ -252,6 +260,7 @@ impl<P, T> Hash for CopyTaggedPtr<P, T, true>
|
|||||||
P: Pointer,
|
P: Pointer,
|
||||||
T: Tag,
|
T: Tag,
|
||||||
{
|
{
|
||||||
|
#[inline]
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
self.packed.hash(state);
|
self.packed.hash(state);
|
||||||
}
|
}
|
||||||
|
@ -30,16 +30,19 @@ impl<P, T, const CP: bool> TaggedPtr<P, T, CP>
|
|||||||
T: Tag,
|
T: Tag,
|
||||||
{
|
{
|
||||||
/// Tags `pointer` with `tag`.
|
/// Tags `pointer` with `tag`.
|
||||||
|
#[inline]
|
||||||
pub fn new(pointer: P, tag: T) -> Self {
|
pub fn new(pointer: P, tag: T) -> Self {
|
||||||
TaggedPtr { raw: CopyTaggedPtr::new(pointer, tag) }
|
TaggedPtr { raw: CopyTaggedPtr::new(pointer, tag) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves the tag.
|
/// Retrieves the tag.
|
||||||
|
#[inline]
|
||||||
pub fn tag(&self) -> T {
|
pub fn tag(&self) -> T {
|
||||||
self.raw.tag()
|
self.raw.tag()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the tag to a new value.
|
/// Sets the tag to a new value.
|
||||||
|
#[inline]
|
||||||
pub fn set_tag(&mut self, tag: T) {
|
pub fn set_tag(&mut self, tag: T) {
|
||||||
self.raw.set_tag(tag)
|
self.raw.set_tag(tag)
|
||||||
}
|
}
|
||||||
@ -63,6 +66,8 @@ impl<P, T, const CP: bool> Deref for TaggedPtr<P, T, CP>
|
|||||||
T: Tag,
|
T: Tag,
|
||||||
{
|
{
|
||||||
type Target = P::Target;
|
type Target = P::Target;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
self.raw.deref()
|
self.raw.deref()
|
||||||
}
|
}
|
||||||
@ -73,6 +78,7 @@ impl<P, T, const CP: bool> DerefMut for TaggedPtr<P, T, CP>
|
|||||||
P: Pointer + DerefMut,
|
P: Pointer + DerefMut,
|
||||||
T: Tag,
|
T: Tag,
|
||||||
{
|
{
|
||||||
|
#[inline]
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
self.raw.deref_mut()
|
self.raw.deref_mut()
|
||||||
}
|
}
|
||||||
@ -108,6 +114,7 @@ impl<P, T> PartialEq for TaggedPtr<P, T, true>
|
|||||||
P: Pointer,
|
P: Pointer,
|
||||||
T: Tag,
|
T: Tag,
|
||||||
{
|
{
|
||||||
|
#[inline]
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.raw.eq(&other.raw)
|
self.raw.eq(&other.raw)
|
||||||
}
|
}
|
||||||
@ -125,6 +132,7 @@ impl<P, T> Hash for TaggedPtr<P, T, true>
|
|||||||
P: Pointer,
|
P: Pointer,
|
||||||
T: Tag,
|
T: Tag,
|
||||||
{
|
{
|
||||||
|
#[inline]
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
self.raw.hash(state);
|
self.raw.hash(state);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user