Format component allocator #21373

This commit is contained in:
kingdido999 2018-08-16 15:44:54 +08:00
parent 89ab110357
commit b25a01f492

View file

@ -9,7 +9,6 @@ static ALLOC: Allocator = Allocator;
pub use platform::*; pub use platform::*;
#[cfg(not(windows))] #[cfg(not(windows))]
mod platform { mod platform {
extern crate jemalloc_sys as ffi; extern crate jemalloc_sys as ffi;
@ -31,19 +30,31 @@ mod platform {
// The minimum alignment guaranteed by the architecture. This value is used to // The minimum alignment guaranteed by the architecture. This value is used to
// add fast paths for low alignment values. // add fast paths for low alignment values.
#[cfg(all(any(target_arch = "arm", #[cfg(
target_arch = "mips", all(
target_arch = "mipsel", any(
target_arch = "powerpc")))] target_arch = "arm",
target_arch = "mips",
target_arch = "mipsel",
target_arch = "powerpc"
)
)
)]
const MIN_ALIGN: usize = 8; const MIN_ALIGN: usize = 8;
#[cfg(all(any(target_arch = "x86", #[cfg(
target_arch = "x86_64", all(
target_arch = "aarch64", any(
target_arch = "powerpc64", target_arch = "x86",
target_arch = "powerpc64le", target_arch = "x86_64",
target_arch = "mips64", target_arch = "aarch64",
target_arch = "s390x", target_arch = "powerpc64",
target_arch = "sparc64")))] target_arch = "powerpc64le",
target_arch = "mips64",
target_arch = "s390x",
target_arch = "sparc64"
)
)
)]
const MIN_ALIGN: usize = 16; const MIN_ALIGN: usize = 16;
fn layout_to_flags(align: usize, size: usize) -> c_int { fn layout_to_flags(align: usize, size: usize) -> c_int {
@ -84,10 +95,7 @@ mod platform {
} }
#[inline] #[inline]
unsafe fn realloc(&self, unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
ptr: *mut u8,
layout: Layout,
new_size: usize) -> *mut u8 {
let flags = layout_to_flags(layout.align(), new_size); let flags = layout_to_flags(layout.align(), new_size);
ffi::rallocx(ptr as *mut _, new_size, flags) as *mut u8 ffi::rallocx(ptr as *mut _, new_size, flags) as *mut u8
} }