Matthias Andreas Benkard | 0858646 | 2020-06-28 22:42:43 +0200 | [diff] [blame] | 1 | //extern "C" fn swap_loop(a: *mut cty::c_char, b: *mut cty::c_char, n: cty::c_int); |
| 2 | |
| 3 | use crate::bindings; |
| 4 | use std::cmp::min; |
| 5 | use std::mem::size_of; |
| 6 | |
| 7 | pub fn cswap_loop<T>(a: &mut [T], b: &mut [T]) { |
| 8 | unsafe { |
| 9 | bindings::swap_loop( |
| 10 | a.as_mut_ptr() as *mut i8, |
| 11 | b.as_mut_ptr() as *mut i8, |
| 12 | (size_of::<T>() * min(a.len(), b.len())) as bindings::size_t, |
| 13 | ) |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | pub fn cswap_malloc<T>(a: &mut [T], b: &mut [T]) { |
| 18 | unsafe { |
| 19 | bindings::swap_malloc( |
| 20 | a.as_mut_ptr() as *mut i8, |
| 21 | b.as_mut_ptr() as *mut i8, |
| 22 | (size_of::<T>() * min(a.len(), b.len())) as bindings::size_t, |
| 23 | ) |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | pub fn cswap_alloca<T>(a: &mut [T], b: &mut [T]) { |
| 28 | unsafe { |
| 29 | bindings::swap_alloca( |
| 30 | a.as_mut_ptr() as *mut i8, |
| 31 | b.as_mut_ptr() as *mut i8, |
| 32 | (size_of::<T>() * min(a.len(), b.len())) as bindings::size_t, |
| 33 | ) |
| 34 | } |
| 35 | } |