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