mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-12 00:00:14 +02:00
Fix Bytes::truncate losing the original Vec's capacity (#361)
This commit is contained in:
committed by
Carl Lerche
parent
729bc7c208
commit
e0eebde993
+9
-1
@@ -418,7 +418,15 @@ impl Bytes {
|
||||
#[inline]
|
||||
pub fn truncate(&mut self, len: usize) {
|
||||
if len < self.len {
|
||||
self.len = 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.
|
||||
if self.vtable as *const Vtable == &PROMOTABLE_EVEN_VTABLE ||
|
||||
self.vtable as *const Vtable == &PROMOTABLE_ODD_VTABLE {
|
||||
drop(self.split_off(len));
|
||||
} else {
|
||||
self.len = len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user