Skip to content

Commit 47e8305

Browse files
authored
Use sub instead of offset (#668)
We're always subtracting here, and we already have a usize, so `sub` seems like a more appropriate usage to me.
1 parent 8bcac21 commit 47e8305

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/bytes_mut.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ impl BytesMut {
617617
//
618618
// Just move the pointer back to the start after copying
619619
// data back.
620-
let base_ptr = self.ptr.as_ptr().offset(-(off as isize));
620+
let base_ptr = self.ptr.as_ptr().sub(off);
621621
// Since `off >= self.len()`, the two regions don't overlap.
622622
ptr::copy_nonoverlapping(self.ptr.as_ptr(), base_ptr, self.len);
623623
self.ptr = vptr(base_ptr);
@@ -1697,7 +1697,7 @@ fn offset_from(dst: *mut u8, original: *mut u8) -> usize {
16971697
}
16981698

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

0 commit comments

Comments
 (0)