Skip to content

Commit 6b04454

Browse files
committed
perf(allocator): #[inline(always)] all Address methods (#15324)
All `Address`'s methods are a single instruction, or complete no-ops. Compiler should inline them, but make sure by marking them all `#[inline(always)]`.
1 parent ef4de9f commit 6b04454

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

crates/oxc_allocator/src/address.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// All methods are 1 instruction or less
2+
#![expect(clippy::inline_always)]
3+
14
use std::ptr::NonNull;
25

36
use crate::Box;
@@ -68,7 +71,7 @@ impl Address {
6871
/// // Address of the `Statement` has changed again
6972
/// assert!(stmt_address_after_insert != stmt_address_after_push);
7073
/// ```
71-
#[inline]
74+
#[inline(always)] // Because it's a no-op
7275
pub fn from_ptr<T>(p: *const T) -> Self {
7376
Self(p as usize)
7477
}
@@ -140,7 +143,7 @@ impl Address {
140143
/// // Address of the `Statement` has changed again
141144
/// assert!(stmt_address_after_insert != stmt_address_after_push);
142145
/// ```
143-
#[inline]
146+
#[inline(always)] // Because it's a no-op
144147
pub fn from_ref<T>(r: &T) -> Self {
145148
let p = NonNull::from_ref(r);
146149
Self(p.addr().get())
@@ -158,7 +161,7 @@ impl<T> GetAddress for Box<'_, T> {
158161
///
159162
/// AST nodes in a `Box` in an arena are guaranteed to never move in memory,
160163
/// so this address acts as a unique identifier for the duration of the arena's existence.
161-
#[inline]
164+
#[inline(always)] // Because it's only 1 instruction
162165
fn address(&self) -> Address {
163166
let ptr = Box::as_non_null(self).as_ptr().cast_const();
164167
Address::from_ptr(ptr)
@@ -167,7 +170,7 @@ impl<T> GetAddress for Box<'_, T> {
167170

168171
impl GetAddress for Address {
169172
/// Address of an `Address` is itself.
170-
#[inline]
173+
#[inline(always)] // Because it's a no-op
171174
fn address(&self) -> Address {
172175
*self
173176
}

0 commit comments

Comments
 (0)