Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify <Vec<u8> as BufMut>::bytes_mut() #442

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/buf/buf_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,15 +1034,15 @@ unsafe impl BufMut for Vec<u8> {

#[inline]
fn bytes_mut(&mut self) -> &mut UninitSlice {
if self.capacity() == self.len() {
let len = self.len();
if self.capacity() == len {
self.reserve(64); // Grow the vec
}

let cap = self.capacity();
let len = self.len();

let ptr = self.as_mut_ptr();
unsafe { &mut UninitSlice::from_raw_parts_mut(ptr, cap)[len..] }
unsafe { UninitSlice::from_raw_parts_mut(ptr.add(len), cap - len) }
}

// Specialize these methods so they can skip checking `remaining_mut`
Expand All @@ -1069,6 +1069,7 @@ unsafe impl BufMut for Vec<u8> {
}
}

#[inline]
fn put_slice(&mut self, src: &[u8]) {
self.extend_from_slice(src);
}
Expand Down