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

Resize refactor #696

Merged
merged 8 commits into from
Apr 24, 2024
Merged
Changes from 1 commit
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
Next Next commit
use checked_sub
  • Loading branch information
braddunbar committed Apr 21, 2024
commit 22dd5839741c88295c1b64d71b1f620056cf51cb
4 changes: 1 addition & 3 deletions src/bytes_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,7 @@ impl BytesMut {
/// assert_eq!(&buf[..], &[0x1, 0x1, 0x3, 0x3]);
/// ```
pub fn resize(&mut self, new_len: usize, value: u8) {
let len = self.len();
if new_len > len {
let additional = new_len - len;
if let Some(additional) = new_len.checked_sub(self.len()) {
self.reserve(additional);
unsafe {
let dst = self.chunk_mut().as_mut_ptr();
Expand Down