File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,29 @@ macro_rules! fill_via_chunks {
59
59
let chunk_size_u8 = min( $src. len( ) * SIZE , $dst. len( ) ) ;
60
60
let chunk_size = ( chunk_size_u8 + SIZE - 1 ) / SIZE ;
61
61
62
+ if cfg!( target_endian = "little" ) {
63
+ unsafe {
64
+ core:: ptr:: copy_nonoverlapping(
65
+ $src. as_ptr( ) as * const u8 ,
66
+ $dst. as_mut_ptr( ) ,
67
+ chunk_size_u8) ;
68
+ }
69
+ } else {
70
+ for ( & n, chunk) in $src. iter( ) . zip( $dst. chunks_mut( SIZE ) ) {
71
+ let tmp = n. to_le( ) ;
72
+ let src_ptr = & tmp as * const $ty as * const u8 ;
73
+ unsafe {
74
+ core:: ptr:: copy_nonoverlapping(
75
+ src_ptr,
76
+ chunk. as_mut_ptr( ) ,
77
+ chunk. len( ) ) ;
78
+ }
79
+ }
80
+ }
81
+
82
+ // The following code is a safe replacement, but unfortunately ca. 8%
83
+ // slower.
84
+ /*
62
85
let mut iter_src = $src.iter();
63
86
let mut chunks = $dst.chunks_exact_mut(SIZE);
64
87
for (chunk, n) in (&mut chunks).zip(&mut iter_src) {
@@ -68,6 +91,7 @@ macro_rules! fill_via_chunks {
68
91
if let Some(n) = iter_src.next() {
69
92
rem.copy_from_slice(&n.to_le_bytes()[..rem.len()]);
70
93
}
94
+ */
71
95
72
96
( chunk_size, chunk_size_u8)
73
97
} } ;
You can’t perform that action at this time.
0 commit comments