blob: 44db6db7d28e2a717e5fa57311006ca5948ca13e [file] [log] [blame]
Matthias Andreas Benkard08586462020-06-28 22:42:43 +02001use crate::bindings;
2use std::cmp::min;
3use std::mem::size_of;
4
5pub 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
15pub 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
25pub 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}