File tree 1 file changed +9
-3
lines changed
library/std/src/sys/pal/windows
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());
94
94
// a non-null handle returned by `GetProcessHeap`.
95
95
#[ inline]
96
96
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 {
100
101
let heap = unsafe { GetProcessHeap ( ) } ;
101
102
if !heap. is_null ( ) {
102
103
// SAFETY: No locking is needed because within the same process,
@@ -109,6 +110,11 @@ fn init_or_get_process_heap() -> c::HANDLE {
109
110
// Could not get the current process heap.
110
111
ptr:: null_mut ( )
111
112
}
113
+ }
114
+
115
+ let heap = HEAP . load ( Ordering :: Relaxed ) ;
116
+ if heap. is_null ( ) {
117
+ init_process_heap ( )
112
118
} else {
113
119
// SAFETY: `HEAP` contains a non-null handle returned by `GetProcessHeap`
114
120
heap
You can’t perform that action at this time.
0 commit comments