Skip to content

Commit

Permalink
Improve comment for make_mut and remove unecessary checked_sub
Browse files Browse the repository at this point in the history
  • Loading branch information
Sytten committed May 5, 2024
1 parent ba06c9a commit 17fd79d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,10 @@ impl Bytes {

/// Try to convert self into `BytesMut`.
///
/// If `self` is unique, this will succeed and return a `BytesMut` with
/// the contents of `self` without copying. If `self` is not unique, this
/// will fail and return self.
/// If `self` is unique for the entire original buffer, this will succeed
/// and return a `BytesMut` with the contents of `self` without copying.
/// If `self` is not unique for the entire original buffer, this will fail
/// and return self.
///
/// # Examples
///
Expand All @@ -532,8 +533,10 @@ impl Bytes {

/// Convert self into `BytesMut`.
///
/// If `self` is unique, it will `BytesMut` with the contents of `self` without copying.
/// If `self` is not unique, it will make a copy of the data.
/// If `self` is unique for the entire original buffer, this will return a
/// `BytesMut` with the contents of `self` without copying.
/// If `self` is not unique for the entire original buffer, this will make
/// a copy of `self` subset of the original buffer in a new `BytesMut`.
///
/// # Examples
///
Expand Down
2 changes: 1 addition & 1 deletion src/bytes_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1760,7 +1760,7 @@ unsafe fn shared_v_to_mut(data: &AtomicPtr<()>, ptr: *const u8, len: usize) -> B
let v_capacity = v.capacity();
let v_ptr = v.as_mut_ptr();
let offset = offset_from(ptr as *mut u8, v_ptr);
let cap = v_capacity.checked_sub(offset).unwrap_or(len);
let cap = v_capacity - offset;

let ptr = vptr(ptr as *mut u8);

Expand Down

0 comments on commit 17fd79d

Please sign in to comment.