blob: b5094813219fc99e25d92249cad46096353acb69 [file] [log] [blame]
Matthias Andreas Benkard08586462020-06-28 22:42:43 +02001//extern "C" fn swap_loop(a: *mut cty::c_char, b: *mut cty::c_char, n: cty::c_int);
2
3use crate::bindings;
4use std::cmp::min;
5use std::mem::size_of;
6
7pub 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
17pub 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
27pub 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}