Skip to content

Commit 00346c9

Browse files
committed
use core::ptr::copy_nonoverlapping as suggested
1 parent dd98ad6 commit 00346c9

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

embedded-io-async/src/impls/slice_mut.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,9 @@ impl Write for &mut [MaybeUninit<u8>] {
4343
return Err(SliceWriteError::Full);
4444
}
4545
let (a, b) = mem::take(self).split_at_mut(amt);
46-
buf.split_at(amt)
47-
.0
48-
.iter()
49-
.enumerate()
50-
.for_each(|(index, byte)| {
51-
a[index].write(*byte);
52-
});
46+
unsafe {
47+
core::ptr::copy_nonoverlapping(buf.as_ptr(), a.as_mut_ptr() as *mut u8, amt);
48+
}
5349
*self = b;
5450
Ok(amt)
5551
}

embedded-io/src/impls/slice_mut.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,9 @@ impl Write for &mut [MaybeUninit<u8>] {
7575
return Err(SliceWriteError::Full);
7676
}
7777
let (a, b) = mem::take(self).split_at_mut(amt);
78-
buf.split_at(amt)
79-
.0
80-
.iter()
81-
.enumerate()
82-
.for_each(|(index, byte)| {
83-
a[index].write(*byte);
84-
});
78+
unsafe {
79+
core::ptr::copy_nonoverlapping(buf.as_ptr(), a.as_mut_ptr() as *mut u8, amt);
80+
}
8581
*self = b;
8682
Ok(amt)
8783
}

0 commit comments

Comments
 (0)