Skip to content

Commit

Permalink
use offset_from consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
braddunbar committed May 5, 2024
1 parent 2be302e commit faa8f5c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ unsafe fn promotable_to_vec(

let buf = f(shared);

let cap = (ptr as usize - buf as usize) + len;
let cap = offset_from(ptr, buf) + len;

// Copy back buffer
ptr::copy(ptr, buf, len);
Expand Down Expand Up @@ -1150,7 +1150,7 @@ unsafe fn promotable_is_unique(data: &AtomicPtr<()>) -> bool {
}

unsafe fn free_boxed_slice(buf: *mut u8, offset: *const u8, len: usize) {
let cap = (offset as usize - buf as usize) + len;
let cap = offset_from(offset, buf) + len;
dealloc(buf, Layout::from_size_align(cap, 1).unwrap())
}

Expand Down Expand Up @@ -1312,7 +1312,7 @@ unsafe fn shallow_clone_vec(
// vector.
let shared = Box::new(Shared {
buf,
cap: (offset as usize - buf as usize) + len,
cap: offset_from(offset, buf) + len,
// Initialize refcount to 2. One for this reference, and one
// for the new clone that will be returned from
// `shallow_clone`.
Expand Down

0 comments on commit faa8f5c

Please sign in to comment.