File tree 1 file changed +21
-0
lines changed
1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -479,6 +479,27 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
479
479
ptr:: copy_nonoverlapping ( t, y. offset ( i) , block_size) ;
480
480
i += block_size as isize ;
481
481
}
482
+
483
+ // Swap remaining bytes 8 at a time if x & y are properly aligned
484
+ if align_of :: < T > ( ) % 8 == 0 {
485
+ while i + 8 <= len as isize {
486
+ let t = * ( x. offset ( i) as * mut u64 ) ;
487
+ * ( x. offset ( i) as * mut u64 ) = * ( y. offset ( i) as * mut u64 ) ;
488
+ * ( y. offset ( i) as * mut u64 ) = t;
489
+ i += 8 ;
490
+ }
491
+ }
492
+
493
+ // Swap remaining bytes 4 at a time if x & y are properly aligned
494
+ if align_of :: < T > ( ) % 4 == 0 {
495
+ while i + 4 <= len as isize {
496
+ let t = * ( x. offset ( i) as * mut u32 ) ;
497
+ * ( x. offset ( i) as * mut u32 ) = * ( y. offset ( i) as * mut u32 ) ;
498
+ * ( y. offset ( i) as * mut u32 ) = t;
499
+ i += 4 ;
500
+ }
501
+ }
502
+
482
503
if i < len {
483
504
// Swap any remaining bytes
484
505
let mut t: UnalignedBlock = uninitialized ( ) ;
You can’t perform that action at this time.
0 commit comments