Skip to content

Commit b6f3424

Browse files
committed
perf(allocator): add #[inline(always)] to trivial RawVec methods (#15470)
These methods are trivial, and should always be inlined. Probably compiler will anyway, but make sure by adding `#[inline(always)]` attributes, same as for `RawVec`'s other trivial methods.
1 parent 732205e commit b6f3424

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

crates/oxc_allocator/src/vec2/raw_vec.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub struct RawVec<'a, T, A: Alloc> {
8080
impl<'a, T, A: Alloc> RawVec<'a, T, A> {
8181
/// Like `new` but parameterized over the choice of allocator for
8282
/// the returned RawVec.
83+
#[inline(always)]
8384
pub fn new_in(alloc: &'a A) -> Self {
8485
// `cap: 0` means "unallocated". zero-sized types are ignored.
8586
RawVec { ptr: NonNull::dangling(), alloc, cap: 0, len: 0 }
@@ -128,6 +129,7 @@ impl<'a, T, A: Alloc> RawVec<'a, T, A> {
128129
///
129130
/// If all these values came from a `Vec` created in allocator `a`, then these requirements
130131
/// are guaranteed to be fulfilled.
132+
#[inline(always)]
131133
pub unsafe fn from_raw_parts_in(ptr: *mut T, len: usize, cap: usize, alloc: &'a A) -> Self {
132134
// SAFETY: Caller guarantees `ptr` was allocated, which implies it's not null
133135
let ptr = unsafe { NonNull::new_unchecked(ptr) };
@@ -141,9 +143,10 @@ impl<'a, T, A: Alloc> RawVec<'a, T, A> {
141143
RawVec { ptr, len, cap, alloc }
142144
}
143145

144-
/// Gets a raw pointer to the start of the allocation. Note that this is
145-
/// Unique::empty() if `cap = 0` or T is zero-sized. In the former case, you must
146-
/// be careful.
146+
/// Gets a raw pointer to the start of the allocation.
147+
/// Note that this is `NonNull::dangling()` if `cap = 0` or T is zero-sized.
148+
/// In the former case, you must be careful.
149+
#[inline(always)]
147150
pub fn ptr(&self) -> *mut T {
148151
self.ptr.as_ptr()
149152
}
@@ -234,10 +237,12 @@ impl<'a, T, A: Alloc> RawVec<'a, T, A> {
234237
/// Caller must ensure they have exclusive access, but holding a `&mut Vec` or `&mut RawVec`
235238
/// for the duration that the reference returned by this method is held.
236239
/// See text above for further detail.
240+
#[inline(always)]
237241
pub unsafe fn bump(&self) -> &'a A {
238242
self.alloc
239243
}
240244

245+
#[inline]
241246
fn current_layout(&self) -> Option<Layout> {
242247
if self.cap == 0 {
243248
None

0 commit comments

Comments
 (0)