Release shared reference on zero truncate (#842)

Co-authored-by: JSap0914 <[email protected]>
This commit is contained in:
JSap0914
2026-07-16 12:19:37 +02:00
committed by GitHub
co-authored by JSap0914
parent 002df10b8c
commit d5c8ad3227
2 changed files with 28 additions and 1 deletions
+3 -1
View File
@@ -567,7 +567,9 @@ impl Bytes {
/// ```
#[inline]
pub fn truncate(&mut self, len: usize) {
if len < self.len {
if len == 0 {
drop(mem::replace(self, Bytes::new_empty_with_ptr(self.ptr)));
} else if len < self.len {
// The Vec "promotable" vtables do not store the capacity,
// so we cannot truncate while using this repr. We *have* to
// promote using `split_off` so the capacity can be stored.