blob: a11f30388adef33ec17e084c46af9a23d89032e3 [file] [log] [blame]
Matthias Andreas Benkard6219ab82020-06-29 19:42:29 +02001use crate::swapper::Swapper;
2
3use core::{mem, ptr};
4use std::cmp::min;
5
6pub struct LoopSwapper {}
7impl Swapper for LoopSwapper {
8 fn swap<T>(a: &mut [T], b: &mut [T]) {
9 for (x, y) in a.iter_mut().zip(b.iter_mut()) {
10 mem::swap(x, y);
11 }
12 }
13}
14
15pub struct PtrSwapper {}
16impl Swapper for PtrSwapper {
17 fn swap<T>(a: &mut [T], b: &mut [T]) {
18 unsafe { ptr::swap_nonoverlapping(a.as_mut_ptr(), b.as_mut_ptr(), min(a.len(), b.len())) }
19 }
20}