Skip to content

Commit 936e0fd

Browse files
committed
Wrap GetProcessHeap and make it never inline
1 parent d9d89fd commit 936e0fd

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

library/std/src/sys/pal/windows/alloc.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ static HEAP: AtomicPtr<c_void> = AtomicPtr::new(ptr::null_mut());
9494
// a non-null handle returned by `GetProcessHeap`.
9595
#[inline]
9696
fn init_or_get_process_heap() -> c::HANDLE {
97-
let heap = HEAP.load(Ordering::Relaxed);
98-
if heap.is_null() {
99-
// `HEAP` has not yet been successfully initialized
97+
// The method is marked never inline to shrink the binary size. It won't be called many times.
98+
#[cold]
99+
#[inline(never)]
100+
fn init_process_heap() -> c::HANDLE {
100101
let heap = unsafe { GetProcessHeap() };
101102
if !heap.is_null() {
102103
// SAFETY: No locking is needed because within the same process,
@@ -109,6 +110,11 @@ fn init_or_get_process_heap() -> c::HANDLE {
109110
// Could not get the current process heap.
110111
ptr::null_mut()
111112
}
113+
}
114+
115+
let heap = HEAP.load(Ordering::Relaxed);
116+
if heap.is_null() {
117+
init_process_heap()
112118
} else {
113119
// SAFETY: `HEAP` contains a non-null handle returned by `GetProcessHeap`
114120
heap

0 commit comments

Comments
 (0)