mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-16 00:00:15 +02:00
Release shared reference on zero truncate (#842)
Co-authored-by: JSap0914 <[email protected]>
This commit is contained in:
+3
-1
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user