| //extern "C" fn swap_loop(a: *mut cty::c_char, b: *mut cty::c_char, n: cty::c_int); |
| |
| use crate::bindings; |
| use std::cmp::min; |
| use std::mem::size_of; |
| |
| pub fn cswap_loop<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 fn cswap_malloc<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 fn cswap_alloca<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, |
| ) |
| } |
| } |