mirror of
https://github.com/actix/actix-extras.git
synced 2025-01-23 07:14:35 +01:00
Preallocate read buffer for h1 codec, #749
This commit is contained in:
parent
1bd0995d7a
commit
c27fbdc35f
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
* Rust 1.31.0 compatibility
|
* Rust 1.31.0 compatibility
|
||||||
|
|
||||||
|
* Preallocate read buffer for h1 codec
|
||||||
|
|
||||||
|
|
||||||
## [0.1.0-alpha.2] - 2019-03-29
|
## [0.1.0-alpha.2] - 2019-03-29
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-http"
|
name = "actix-http"
|
||||||
version = "0.1.0-alpha.2"
|
version = "0.1.0-alpha.3"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix http primitives"
|
description = "Actix http primitives"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -19,6 +19,9 @@ use crate::message::{ConnectionType, Head, ResponseHead};
|
|||||||
use crate::request::Request;
|
use crate::request::Request;
|
||||||
use crate::response::Response;
|
use crate::response::Response;
|
||||||
|
|
||||||
|
const LW: usize = 2 * 1024;
|
||||||
|
const HW: usize = 32 * 1024;
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
struct Flags: u8 {
|
struct Flags: u8 {
|
||||||
const HEAD = 0b0000_0001;
|
const HEAD = 0b0000_0001;
|
||||||
@ -105,6 +108,11 @@ impl Decoder for Codec {
|
|||||||
type Error = ParseError;
|
type Error = ParseError;
|
||||||
|
|
||||||
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
|
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
|
||||||
|
let cap = src.capacity();
|
||||||
|
if cap < LW {
|
||||||
|
src.reserve(HW - cap);
|
||||||
|
}
|
||||||
|
|
||||||
if self.payload.is_some() {
|
if self.payload.is_some() {
|
||||||
Ok(match self.payload.as_mut().unwrap().decode(src)? {
|
Ok(match self.payload.as_mut().unwrap().decode(src)? {
|
||||||
Some(PayloadItem::Chunk(chunk)) => Some(Message::Chunk(Some(chunk))),
|
Some(PayloadItem::Chunk(chunk)) => Some(Message::Chunk(Some(chunk))),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user