1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-05-20 09:18:26 +00:00

minor optimization: reserve buffer once length is known (ws) (#2950)

This commit is contained in:
moh-eulith 2023-05-07 11:13:10 -04:00 committed by GitHub
parent 6fdda45ca3
commit 17218dc6c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,3 +1,4 @@
use std::cmp::min;
use std::convert::TryFrom;
use bytes::{Buf, BufMut, BytesMut};
@ -96,6 +97,10 @@ impl Parser {
// not enough data
if src.len() < idx + length {
let min_length = min(length, max_size);
if src.capacity() < idx + min_length {
src.reserve(idx + min_length - src.capacity());
}
return Ok(None);
}