Skip to content

Commit

Permalink
inline
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Jul 15, 2024
1 parent 3e3a27b commit c6224ac
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/swc_allocator/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl FastAlloc {

/// `true` is passed to `f` if the box is allocated with a custom allocator.
#[cfg(not(feature = "scoped"))]
#[inline(always)]
fn with_allocator<T>(&self, f: impl FnOnce(allocator_api2::alloc::Global, bool) -> T) -> T {
f(allocator_api2::alloc::Global, false)
}
Expand All @@ -82,6 +83,7 @@ fn mark_ptr_as_arena_mode(ptr: NonNull<[u8]>) -> NonNull<[u8]> {
}

unsafe impl allocator_api2::alloc::Allocator for FastAlloc {
#[inline]
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, allocator_api2::alloc::AllocError> {
self.with_allocator(|a, is_arena_mode| {
let ptr = a.allocate(layout)?;
Expand All @@ -94,6 +96,7 @@ unsafe impl allocator_api2::alloc::Allocator for FastAlloc {
})
}

#[inline]
fn allocate_zeroed(
&self,
layout: Layout,
Expand All @@ -109,6 +112,7 @@ unsafe impl allocator_api2::alloc::Allocator for FastAlloc {
})
}

#[inline]
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
#[cfg(feature = "scoped")]
if self.alloc.is_some() {
Expand All @@ -124,6 +128,7 @@ unsafe impl allocator_api2::alloc::Allocator for FastAlloc {
Global.deallocate(ptr, layout)
}

#[inline]
unsafe fn grow(
&self,
ptr: NonNull<u8>,
Expand All @@ -141,6 +146,7 @@ unsafe impl allocator_api2::alloc::Allocator for FastAlloc {
})
}

#[inline]
unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
Expand All @@ -158,6 +164,7 @@ unsafe impl allocator_api2::alloc::Allocator for FastAlloc {
})
}

#[inline]
unsafe fn shrink(
&self,
ptr: NonNull<u8>,
Expand All @@ -175,6 +182,7 @@ unsafe impl allocator_api2::alloc::Allocator for FastAlloc {
})
}

#[inline(always)]
fn by_ref(&self) -> &Self
where
Self: Sized,
Expand Down

0 comments on commit c6224ac

Please sign in to comment.