blob: a9d7733c1dc61ff292d9018ca13bec9a5e1f74cf [file] [log] [blame]
use crate::bindings;
use crate::swapper::Swapper;
use std::cmp::min;
use std::mem::size_of;
pub struct CLoopSwapper {}
impl Swapper for CLoopSwapper {
fn swap<T>(a: &mut [T], b: &mut [T]) {
unsafe {
bindings::swap_loop(
a.as_mut_ptr() as *mut i8,
b.as_mut_ptr() as *mut i8,
(size_of::<T>() * min(a.len(), b.len())) as bindings::size_t,
)
}
}
}
pub struct CMallocSwapper {}
impl Swapper for CMallocSwapper {
fn swap<T>(a: &mut [T], b: &mut [T]) {
unsafe {
bindings::swap_malloc(
a.as_mut_ptr() as *mut i8,
b.as_mut_ptr() as *mut i8,
(size_of::<T>() * min(a.len(), b.len())) as bindings::size_t,
)
}
}
}
pub struct CAllocaSwapper {}
impl Swapper for CAllocaSwapper {
fn swap<T>(a: &mut [T], b: &mut [T]) {
unsafe {
bindings::swap_alloca(
a.as_mut_ptr() as *mut i8,
b.as_mut_ptr() as *mut i8,
(size_of::<T>() * min(a.len(), b.len())) as bindings::size_t,
)
}
}
}