Skip to content

Commit 0039523

Browse files
committed
refactor(tasks/track_memory_allocations): shorten code (#12931)
Pure refactor. Shorten code by hoisting import of `MiMalloc` to top level, and tweak formatting.
1 parent 87ac156 commit 0039523

File tree

1 file changed

+6
-6
lines changed
  • tasks/track_memory_allocations/src

1 file changed

+6
-6
lines changed

tasks/track_memory_allocations/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{
77
};
88

99
use humansize::{DECIMAL, format_size};
10+
use mimalloc_safe::MiMalloc;
1011

1112
use oxc_allocator::Allocator;
1213
use oxc_parser::{ParseOptions, Parser};
@@ -38,28 +39,27 @@ fn reset_global_allocs() {
3839
#[expect(unsafe_code, clippy::undocumented_unsafe_blocks)]
3940
unsafe impl GlobalAlloc for TrackedAllocator {
4041
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
41-
let ret = unsafe { mimalloc_safe::MiMalloc.alloc(layout) };
42+
let ret = unsafe { MiMalloc.alloc(layout) };
4243
if !ret.is_null() {
4344
NUM_ALLOC.fetch_add(1, SeqCst);
4445
}
4546
ret
4647
}
4748

4849
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
49-
unsafe {
50-
mimalloc_safe::MiMalloc.dealloc(ptr, layout);
51-
}
50+
unsafe { MiMalloc.dealloc(ptr, layout) };
5251
}
5352

5453
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
55-
let ret = unsafe { mimalloc_safe::MiMalloc.alloc_zeroed(layout) };
54+
let ret = unsafe { MiMalloc.alloc_zeroed(layout) };
5655
if !ret.is_null() {
5756
NUM_ALLOC.fetch_add(1, SeqCst);
5857
}
5958
ret
6059
}
60+
6161
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
62-
let ret = unsafe { mimalloc_safe::MiMalloc.realloc(ptr, layout, new_size) };
62+
let ret = unsafe { MiMalloc.realloc(ptr, layout, new_size) };
6363
if !ret.is_null() {
6464
NUM_REALLOC.fetch_add(1, SeqCst);
6565
}

0 commit comments

Comments
 (0)