Skip to content

Commit

Permalink
Don't set len in BytesMut::reserve
Browse files Browse the repository at this point in the history
A fundamental invariant of `reserve` is that it can extend capacity
while the stored data remains the same, even if it's moved to a new
allocation. As a result, `len` can never change during a call to
`reserve`.
  • Loading branch information
braddunbar committed Mar 24, 2024
1 parent ce8d8a0 commit 6744316
Showing 1 changed file with 0 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/bytes_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ impl BytesMut {

// Update the info
self.ptr = vptr(v.as_mut_ptr().add(off));
self.len = v.len() - off;
self.cap = v.capacity() - off;
}

Expand Down Expand Up @@ -746,7 +745,6 @@ impl BytesMut {
let data = (original_capacity_repr << ORIGINAL_CAPACITY_OFFSET) | KIND_VEC;
self.data = invalid_ptr(data);
self.ptr = vptr(v.as_mut_ptr());
self.len = v.len();
self.cap = v.capacity();
}

Expand Down

0 comments on commit 6744316

Please sign in to comment.