mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-07 00:00:13 +02:00
Calculate original capacity only if necessary (#666)
We don't need the original capacity if the shared data is unique, so let's not calculate it until after that check.
This commit is contained in:
+3
-6
@@ -652,13 +652,7 @@ impl BytesMut {
|
|||||||
// Compute the new capacity
|
// Compute the new capacity
|
||||||
let mut new_cap = len.checked_add(additional).expect("overflow");
|
let mut new_cap = len.checked_add(additional).expect("overflow");
|
||||||
|
|
||||||
let original_capacity;
|
|
||||||
let original_capacity_repr;
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
original_capacity_repr = (*shared).original_capacity_repr;
|
|
||||||
original_capacity = original_capacity_from_repr(original_capacity_repr);
|
|
||||||
|
|
||||||
// First, try to reclaim the buffer. This is possible if the current
|
// First, try to reclaim the buffer. This is possible if the current
|
||||||
// handle is the only outstanding handle pointing to the buffer.
|
// handle is the only outstanding handle pointing to the buffer.
|
||||||
if (*shared).is_unique() {
|
if (*shared).is_unique() {
|
||||||
@@ -729,6 +723,9 @@ impl BytesMut {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let original_capacity_repr = unsafe { (*shared).original_capacity_repr };
|
||||||
|
let original_capacity = original_capacity_from_repr(original_capacity_repr);
|
||||||
|
|
||||||
new_cap = cmp::max(new_cap, original_capacity);
|
new_cap = cmp::max(new_cap, original_capacity);
|
||||||
|
|
||||||
// Create a new vector to store the data
|
// Create a new vector to store the data
|
||||||
|
|||||||
Reference in New Issue
Block a user