@@ -29,33 +29,6 @@ use core::alloc::{GlobalAlloc, Layout};
29
29
use core:: ffi:: c_void;
30
30
use ffi:: * ;
31
31
32
- // `MI_MAX_ALIGN_SIZE` is 16 unless manually overridden:
33
- // https://github.com/microsoft/mimalloc/blob/15220c68/include/mimalloc-types.h#L22
34
- //
35
- // If it changes on us, we should consider either manually overriding it, or
36
- // expose it from the -sys crate (in order to catch updates)
37
- const MI_MAX_ALIGN_SIZE : usize = 16 ;
38
-
39
- // Note: this doesn't take a layout directly because doing so would be wrong for
40
- // reallocation
41
- #[ inline]
42
- fn may_use_unaligned_api ( size : usize , alignment : usize ) -> bool {
43
- // Required by `GlobalAlloc`. Note that while allocators aren't allowed to
44
- // unwind in rust, this is only in debug mode, and can only happen if the
45
- // caller already caused UB by passing in an invalid layout.
46
- debug_assert ! ( size != 0 && alignment. is_power_of_two( ) ) ;
47
-
48
- // This logic is based on the discussion [here]. We don't bother with the
49
- // 3rd suggested test due to it being high cost (calling `mi_good_size`)
50
- // compared to the other checks, and also feeling like it relies on too much
51
- // implementation-specific behavior.
52
- //
53
- // [here]: https://github.com/microsoft/mimalloc/issues/314#issuecomment-708541845
54
-
55
- ( alignment <= MI_MAX_ALIGN_SIZE && size >= alignment)
56
- || ( alignment == size && alignment <= 4096 )
57
- }
58
-
59
32
/// Drop-in mimalloc global allocator.
60
33
///
61
34
/// ## Usage
@@ -70,20 +43,12 @@ pub struct MiMalloc;
70
43
unsafe impl GlobalAlloc for MiMalloc {
71
44
#[ inline]
72
45
unsafe fn alloc ( & self , layout : Layout ) -> * mut u8 {
73
- if may_use_unaligned_api ( layout. size ( ) , layout. align ( ) ) {
74
- mi_malloc ( layout. size ( ) ) as * mut u8
75
- } else {
76
- mi_malloc_aligned ( layout. size ( ) , layout. align ( ) ) as * mut u8
77
- }
46
+ mi_malloc_aligned ( layout. size ( ) , layout. align ( ) ) as * mut u8
78
47
}
79
48
80
49
#[ inline]
81
50
unsafe fn alloc_zeroed ( & self , layout : Layout ) -> * mut u8 {
82
- if may_use_unaligned_api ( layout. size ( ) , layout. align ( ) ) {
83
- mi_zalloc ( layout. size ( ) ) as * mut u8
84
- } else {
85
- mi_zalloc_aligned ( layout. size ( ) , layout. align ( ) ) as * mut u8
86
- }
51
+ mi_zalloc_aligned ( layout. size ( ) , layout. align ( ) ) as * mut u8
87
52
}
88
53
89
54
#[ inline]
@@ -93,11 +58,7 @@ unsafe impl GlobalAlloc for MiMalloc {
93
58
94
59
#[ inline]
95
60
unsafe fn realloc ( & self , ptr : * mut u8 , layout : Layout , new_size : usize ) -> * mut u8 {
96
- if may_use_unaligned_api ( new_size, layout. align ( ) ) {
97
- mi_realloc ( ptr as * mut c_void , new_size) as * mut u8
98
- } else {
99
- mi_realloc_aligned ( ptr as * mut c_void , new_size, layout. align ( ) ) as * mut u8
100
- }
61
+ mi_realloc_aligned ( ptr as * mut c_void , new_size, layout. align ( ) ) as * mut u8
101
62
}
102
63
}
103
64
0 commit comments