File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
library/std/src/sys/pal/windows Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff 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]
9696fn 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
You can’t perform that action at this time.
0 commit comments