diff options
author | 2024-04-09 08:35:54 -0400 | |
---|---|---|
committer | 2024-04-09 14:35:54 +0200 | |
commit | e4af48633cec419e8274571d353fe166d5e23a3e (patch) | |
tree | 3ed439dd8581c5722df491d81131662dd7b93bdb /src | |
parent | 0d4cc7ffed2eadfb2028bade65b9ac0b6d231fc4 (diff) | |
download | bytes-e4af48633cec419e8274571d353fe166d5e23a3e.tar.gz bytes-e4af48633cec419e8274571d353fe166d5e23a3e.tar.zst bytes-e4af48633cec419e8274571d353fe166d5e23a3e.zip |
Don't set `len` in `BytesMut::reserve` (#682)
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`.
Diffstat (limited to 'src')
-rw-r--r-- | src/bytes_mut.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/bytes_mut.rs b/src/bytes_mut.rs index 282aaa7..c9f5634 100644 --- a/src/bytes_mut.rs +++ b/src/bytes_mut.rs @@ -639,8 +639,8 @@ impl BytesMut { // Update the info self.ptr = vptr(v.as_mut_ptr().add(off)); - self.len = v.len() - off; self.cap = v.capacity() - off; + debug_assert_eq!(self.len, v.len() - off); } return; @@ -746,8 +746,8 @@ 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(); + debug_assert_eq!(self.len, v.len()); } /// Appends given bytes to this `BytesMut`. |