Skip to content

Commit ab2c9cd

Browse files
refactor: replace manual implementations of ReadBufCursor methods (#181)
1 parent 3fdf672 commit ab2c9cd

File tree

1 file changed

+2
-30
lines changed

1 file changed

+2
-30
lines changed

src/common/rewind.rs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ where
3737
if let Some(mut prefix) = self.pre.take() {
3838
// If there are no remaining bytes, let the bytes get dropped.
3939
if !prefix.is_empty() {
40-
let copy_len = cmp::min(prefix.len(), remaining(&mut buf));
41-
// TODO: There should be a way to do following two lines cleaner...
42-
put_slice(&mut buf, &prefix[..copy_len]);
40+
let copy_len = cmp::min(prefix.len(), buf.remaining());
41+
buf.put_slice(&prefix[..copy_len]);
4342
prefix.advance(copy_len);
4443
// Put back what's left
4544
if !prefix.is_empty() {
@@ -53,33 +52,6 @@ where
5352
}
5453
}
5554

56-
fn remaining(cursor: &mut ReadBufCursor<'_>) -> usize {
57-
// SAFETY:
58-
// We do not uninitialize any set bytes.
59-
unsafe { cursor.as_mut().len() }
60-
}
61-
62-
// Copied from `ReadBufCursor::put_slice`.
63-
// If that becomes public, we could ditch this.
64-
fn put_slice(cursor: &mut ReadBufCursor<'_>, slice: &[u8]) {
65-
assert!(
66-
remaining(cursor) >= slice.len(),
67-
"buf.len() must fit in remaining()"
68-
);
69-
70-
let amt = slice.len();
71-
72-
// SAFETY:
73-
// the length is asserted above
74-
unsafe {
75-
cursor.as_mut()[..amt]
76-
.as_mut_ptr()
77-
.cast::<u8>()
78-
.copy_from_nonoverlapping(slice.as_ptr(), amt);
79-
cursor.advance(amt);
80-
}
81-
}
82-
8355
impl<T> Write for Rewind<T>
8456
where
8557
T: Write + Unpin,

0 commit comments

Comments
 (0)