mirror of
https://github.com/actix/actix-web.git
synced 2025-01-23 15:38:06 +00:00
minor optimization: reserve buffer once length is known (ws) (#2950)
This commit is contained in:
parent
6fdda45ca3
commit
17218dc6c8
1 changed files with 5 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue