Skip to content

Commit

Permalink
REFAC: use extend_from_slice in Write implementation for ArrayVec
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomasdezeeuw committed Jul 17, 2018
1 parent 876c465 commit fa4e22f
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,16 +1046,9 @@ impl<A: Array> Ord for ArrayVec<A> where A::Item: Ord {
/// Requires `features="std"`.
impl<A: Array<Item=u8>> io::Write for ArrayVec<A> {
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
unsafe {
let len = self.len();
let mut tail = slice::from_raw_parts_mut(self.get_unchecked_mut(len),
A::capacity() - len);
let result = tail.write(data);
if let Ok(written) = result {
self.set_len(len + written);
}
result
}
let len = cmp::min(self.capacity_left(), data.len());
self.extend_from_slice(&data[..len]);
Ok(len)
}
fn flush(&mut self) -> io::Result<()> { Ok(()) }
}
Expand Down

0 comments on commit fa4e22f

Please sign in to comment.