@@ -4,13 +4,13 @@ use crate::util::Address;
4
4
use crate :: util:: Lazy ;
5
5
use crate :: Mutator ;
6
6
use core:: { alloc:: Layout , ptr} ;
7
- use std:: intrinsics :: unlikely ;
7
+ use std:: marker :: PhantomData ;
8
8
9
9
pub trait GetMutatorType {
10
10
type Mutator : Mutator ;
11
11
}
12
12
13
- pub struct MallocAPI < P : Plan > ( & ' static Lazy < P > ) ;
13
+ pub struct MallocAPI < P : Plan > ( PhantomData < P > ) ;
14
14
15
15
impl < P : Plan > GetMutatorType for MallocAPI < P > {
16
16
type Mutator = P :: Mutator ;
@@ -31,7 +31,7 @@ impl<P: Plan> MallocAPI<P> {
31
31
pub const PAGE_SIZE : usize = 4096 ;
32
32
33
33
pub const fn new ( plan : & ' static Lazy < P > ) -> Self {
34
- Self ( plan )
34
+ Self ( PhantomData )
35
35
}
36
36
37
37
pub const fn new_mutator ( ) -> P :: Mutator {
@@ -58,7 +58,7 @@ impl<P: Plan> MallocAPI<P> {
58
58
pub unsafe fn malloc_size ( & self , ptr : Address ) -> usize {
59
59
let ptr = Address :: from ( ptr) ;
60
60
#[ cfg( target_os = "macos" ) ]
61
- if unlikely ( Self :: zero_spaceid ( ptr. into ( ) ) ) {
61
+ if Self :: zero_spaceid ( ptr. into ( ) ) {
62
62
return crate :: util:: macos_malloc_zone:: external_memory_size ( ptr) ;
63
63
}
64
64
P :: get_layout ( ptr) . size ( )
@@ -85,11 +85,11 @@ impl<P: Plan> MallocAPI<P> {
85
85
}
86
86
87
87
pub unsafe fn free ( & self , ptr : * mut u8 ) {
88
- if unlikely ( ptr. is_null ( ) ) {
88
+ if ptr. is_null ( ) {
89
89
return ;
90
90
}
91
91
#[ cfg( target_os = "macos" ) ]
92
- if unlikely ( Self :: zero_spaceid ( ptr. into ( ) ) ) {
92
+ if Self :: zero_spaceid ( ptr. into ( ) ) {
93
93
return ;
94
94
}
95
95
self . mutator ( ) . dealloc ( ptr. into ( ) ) ;
@@ -105,14 +105,14 @@ impl<P: Plan> MallocAPI<P> {
105
105
if ptr. is_null ( ) {
106
106
return self . alloc_or_enomem ( new_size, Self :: MIN_ALIGNMENT ) ;
107
107
}
108
- if unlikely ( free_if_new_size_is_zero && new_size == 0 ) {
108
+ if free_if_new_size_is_zero && new_size == 0 {
109
109
self . free ( ptr) ;
110
110
return ptr:: null_mut ( ) ;
111
111
}
112
112
let new_size = Self :: align_up ( new_size, Self :: MIN_ALIGNMENT ) ;
113
113
114
114
#[ cfg( target_os = "macos" ) ]
115
- if unlikely ( Self :: zero_spaceid ( ptr. into ( ) ) ) {
115
+ if Self :: zero_spaceid ( ptr. into ( ) ) {
116
116
let ptr = Address :: from ( ptr) ;
117
117
let old_size = crate :: util:: macos_malloc_zone:: external_memory_size ( ptr) ;
118
118
let new_layout =
@@ -152,7 +152,7 @@ impl<P: Plan> MallocAPI<P> {
152
152
mut alignment : usize ,
153
153
size : usize ,
154
154
) -> i32 {
155
- if unlikely ( !alignment. is_power_of_two ( ) ) {
155
+ if !alignment. is_power_of_two ( ) {
156
156
return libc:: EINVAL ;
157
157
}
158
158
alignment = std:: cmp:: max ( alignment, Self :: MIN_ALIGNMENT ) ;
@@ -168,7 +168,7 @@ impl<P: Plan> MallocAPI<P> {
168
168
pub unsafe fn memalign ( & self , alignment : usize , size : usize ) -> * mut u8 {
169
169
let mut result = ptr:: null_mut ( ) ;
170
170
let errno = self . posix_memalign ( & mut result, alignment, size) ;
171
- if unlikely ( result. is_null ( ) ) {
171
+ if result. is_null ( ) {
172
172
Self :: set_error ( errno)
173
173
}
174
174
result
@@ -181,11 +181,10 @@ impl<P: Plan> MallocAPI<P> {
181
181
einval_if_size_is_not_aligned : bool ,
182
182
einval_if_size_is_zero : bool ,
183
183
) -> * mut u8 {
184
- if unlikely (
185
- !alignment. is_power_of_two ( )
186
- || ( einval_if_size_is_not_aligned && ( size & ( alignment - 1 ) ) != 0 )
187
- || ( einval_if_size_is_zero && size == 0 ) ,
188
- ) {
184
+ if !alignment. is_power_of_two ( )
185
+ || ( einval_if_size_is_not_aligned && ( size & ( alignment - 1 ) ) != 0 )
186
+ || ( einval_if_size_is_zero && size == 0 )
187
+ {
189
188
Self :: set_error ( libc:: EINVAL ) ;
190
189
return ptr:: null_mut ( ) ;
191
190
}
0 commit comments