mirror of
https://github.com/fafhrd91/actix-web
synced 2025-02-20 03:14:21 +01:00
minor optimization: reserve buffer once length is known (ws) (#2950)
This commit is contained in:
parent
6fdda45ca3
commit
17218dc6c8
@ -1,3 +1,4 @@
|
|||||||
|
use std::cmp::min;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use bytes::{Buf, BufMut, BytesMut};
|
use bytes::{Buf, BufMut, BytesMut};
|
||||||
@ -96,6 +97,10 @@ impl Parser {
|
|||||||
|
|
||||||
// not enough data
|
// not enough data
|
||||||
if src.len() < idx + length {
|
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);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user