File tree 1 file changed +11
-11
lines changed
1 file changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -58,25 +58,25 @@ macro_rules! fill_via_chunks {
58
58
let chunk_size_u8 = min( $src. len( ) * SIZE , $dst. len( ) ) ;
59
59
let chunk_size = ( chunk_size_u8 + SIZE - 1 ) / SIZE ;
60
60
61
- // The following can be replaced with safe code, but unfortunately it's
62
- // ca. 8% slower.
63
61
if cfg!( target_endian = "little" ) {
62
+ // On LE we can do a simple copy, which is 25-50% faster:
64
63
unsafe {
65
64
core:: ptr:: copy_nonoverlapping(
66
65
$src. as_ptr( ) as * const u8 ,
67
66
$dst. as_mut_ptr( ) ,
68
67
chunk_size_u8) ;
69
68
}
70
69
} else {
71
- for ( & n, chunk) in $src. iter( ) . zip( $dst. chunks_mut( SIZE ) ) {
72
- let tmp = n. to_le( ) ;
73
- let src_ptr = & tmp as * const $ty as * const u8 ;
74
- unsafe {
75
- core:: ptr:: copy_nonoverlapping(
76
- src_ptr,
77
- chunk. as_mut_ptr( ) ,
78
- chunk. len( ) ) ;
79
- }
70
+ // This code is valid on all arches, but slower than the above:
71
+ let mut i = 0 ;
72
+ let mut iter = $dst[ ..chunk_size_u8] . chunks_exact_mut( SIZE ) ;
73
+ while let Some ( chunk) = iter. next( ) {
74
+ chunk. copy_from_slice( & $src[ i] . to_le_bytes( ) ) ;
75
+ i += 1 ;
76
+ }
77
+ let chunk = iter. into_remainder( ) ;
78
+ if !chunk. is_empty( ) {
79
+ chunk. copy_from_slice( & $src[ i] . to_le_bytes( ) [ ..chunk. len( ) ] ) ;
80
80
}
81
81
}
82
82
You can’t perform that action at this time.
0 commit comments