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

Do not use thread pool for decomression if chunk size is smaller than 2048

This commit is contained in:
Nikolay Kim 2019-03-28 21:15:26 -07:00
parent 10b166404e
commit 3b897da8e2
3 changed files with 24 additions and 11 deletions

View file

@ -1,5 +1,12 @@
# Changes
## [0.1.0-alpha.2] - 2019-xx-xx
### Changed
* Do not use thread pool for decomression if chunk size is smaller than 2048.
## [0.1.0-alpha.1] - 2019-03-28
* Initial impl

View file

@ -1,6 +1,6 @@
[package]
name = "actix-http"
version = "0.1.0-alpha.1"
version = "0.1.0-alpha.2"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix http primitives"
readme = "README.md"

View file

@ -12,6 +12,8 @@ use super::Writer;
use crate::error::PayloadError;
use crate::http::header::{ContentEncoding, HeaderMap, CONTENT_ENCODING};
const INPLACE: usize = 2049;
pub struct Decoder<S> {
decoder: Option<ContentDecoder>,
stream: S,
@ -92,10 +94,18 @@ where
match self.stream.poll()? {
Async::Ready(Some(chunk)) => {
if let Some(mut decoder) = self.decoder.take() {
if chunk.len() < INPLACE {
let chunk = decoder.feed_data(chunk)?;
self.decoder = Some(decoder);
if let Some(chunk) = chunk {
return Ok(Async::Ready(Some(chunk)));
}
} else {
self.fut = Some(run(move || {
let chunk = decoder.feed_data(chunk)?;
Ok((chunk, decoder))
}));
}
continue;
} else {
return Ok(Async::Ready(Some(chunk)));
@ -103,14 +113,10 @@ where
}
Async::Ready(None) => {
self.eof = true;
if let Some(mut decoder) = self.decoder.take() {
self.fut = Some(run(move || {
let chunk = decoder.feed_eof()?;
Ok((chunk, decoder))
}));
continue;
return if let Some(mut decoder) = self.decoder.take() {
Ok(Async::Ready(decoder.feed_eof()?))
} else {
return Ok(Async::Ready(None));
Ok(Async::Ready(None))
};
}
Async::NotReady => break,