Optimize BytesMut::reserve: Reuse vec if possible (#529)

* Optimize `BytesMut::reserve`: Reuse vec if possible

If the `BytesMut` holds a unqiue reference to `KIND_ARC` while the
capacity of the `Vec` is not big enough , reuse the existing `Vec`
instead of allocating a new one.

Signed-off-by: Jiahao XU <[email protected]>
This commit is contained in:
Jiahao XU
2022-03-16 10:11:42 -04:00
committed by GitHub
parent 88f5e12350
commit d4f5023383
2 changed files with 29 additions and 13 deletions
+1 -1
View File
@@ -443,7 +443,7 @@ fn reserve_growth() {
let _ = bytes.split();
bytes.reserve(65);
assert_eq!(bytes.capacity(), 128);
assert_eq!(bytes.capacity(), 117);
}
#[test]