Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions crates/oxc_allocator/src/address.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// All methods are 1 instruction or less
#![expect(clippy::inline_always)]

use std::ptr::NonNull;

use crate::Box;
Expand Down Expand Up @@ -68,7 +71,7 @@ impl Address {
/// // Address of the `Statement` has changed again
/// assert!(stmt_address_after_insert != stmt_address_after_push);
/// ```
#[inline]
#[inline(always)] // Because it's a no-op
pub fn from_ptr<T>(p: *const T) -> Self {
Self(p as usize)
}
Expand Down Expand Up @@ -140,7 +143,7 @@ impl Address {
/// // Address of the `Statement` has changed again
/// assert!(stmt_address_after_insert != stmt_address_after_push);
/// ```
#[inline]
#[inline(always)] // Because it's a no-op
pub fn from_ref<T>(r: &T) -> Self {
let p = NonNull::from_ref(r);
Self(p.addr().get())
Expand All @@ -158,7 +161,7 @@ impl<T> GetAddress for Box<'_, T> {
///
/// AST nodes in a `Box` in an arena are guaranteed to never move in memory,
/// so this address acts as a unique identifier for the duration of the arena's existence.
#[inline]
#[inline(always)] // Because it's only 1 instruction
fn address(&self) -> Address {
let ptr = Box::as_non_null(self).as_ptr().cast_const();
Address::from_ptr(ptr)
Expand All @@ -167,7 +170,7 @@ impl<T> GetAddress for Box<'_, T> {

impl GetAddress for Address {
/// Address of an `Address` is itself.
#[inline]
#[inline(always)] // Because it's a no-op
fn address(&self) -> Address {
*self
}
Expand Down
Loading