From bf302439965cdab1c364a04cf49d528170371313 Mon Sep 17 00:00:00 2001 From: Mohammad Rezaei Date: Wed, 21 Dec 2022 16:28:09 -0500 Subject: [PATCH] minor optimization: reserve buffer once length is known when reading websockets --- actix-http/src/ws/frame.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/actix-http/src/ws/frame.rs b/actix-http/src/ws/frame.rs index c7e0427ea..dddb03d18 100644 --- a/actix-http/src/ws/frame.rs +++ b/actix-http/src/ws/frame.rs @@ -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); }