Skip to content

Commit

Permalink
Use sub instead of offset (#668)
Browse files Browse the repository at this point in the history
We're always subtracting here, and we already have a usize, so `sub`
seems like a more appropriate usage to me.
  • Loading branch information
braddunbar committed Feb 6, 2024
1 parent 8bcac21 commit 47e8305
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/bytes_mut.rs
Expand Up @@ -617,7 +617,7 @@ impl BytesMut {
//
// Just move the pointer back to the start after copying
// data back.
let base_ptr = self.ptr.as_ptr().offset(-(off as isize));
let base_ptr = self.ptr.as_ptr().sub(off);
// Since `off >= self.len()`, the two regions don't overlap.
ptr::copy_nonoverlapping(self.ptr.as_ptr(), base_ptr, self.len);
self.ptr = vptr(base_ptr);
Expand Down Expand Up @@ -1697,7 +1697,7 @@ fn offset_from(dst: *mut u8, original: *mut u8) -> usize {
}

unsafe fn rebuild_vec(ptr: *mut u8, mut len: usize, mut cap: usize, off: usize) -> Vec<u8> {
let ptr = ptr.offset(-(off as isize));
let ptr = ptr.sub(off);
len += off;
cap += off;

Expand Down

0 comments on commit 47e8305

Please sign in to comment.