mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 07:53:00 +01:00
Do not use thread pool for decomression if chunk size is smaller than 2048
This commit is contained in:
parent
10b166404e
commit
3b897da8e2
@ -1,5 +1,12 @@
|
|||||||
# Changes
|
# 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
|
## [0.1.0-alpha.1] - 2019-03-28
|
||||||
|
|
||||||
* Initial impl
|
* Initial impl
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-http"
|
name = "actix-http"
|
||||||
version = "0.1.0-alpha.1"
|
version = "0.1.0-alpha.2"
|
||||||
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"
|
||||||
|
@ -12,6 +12,8 @@ use super::Writer;
|
|||||||
use crate::error::PayloadError;
|
use crate::error::PayloadError;
|
||||||
use crate::http::header::{ContentEncoding, HeaderMap, CONTENT_ENCODING};
|
use crate::http::header::{ContentEncoding, HeaderMap, CONTENT_ENCODING};
|
||||||
|
|
||||||
|
const INPLACE: usize = 2049;
|
||||||
|
|
||||||
pub struct Decoder<S> {
|
pub struct Decoder<S> {
|
||||||
decoder: Option<ContentDecoder>,
|
decoder: Option<ContentDecoder>,
|
||||||
stream: S,
|
stream: S,
|
||||||
@ -92,10 +94,18 @@ where
|
|||||||
match self.stream.poll()? {
|
match self.stream.poll()? {
|
||||||
Async::Ready(Some(chunk)) => {
|
Async::Ready(Some(chunk)) => {
|
||||||
if let Some(mut decoder) = self.decoder.take() {
|
if let Some(mut decoder) = self.decoder.take() {
|
||||||
self.fut = Some(run(move || {
|
if chunk.len() < INPLACE {
|
||||||
let chunk = decoder.feed_data(chunk)?;
|
let chunk = decoder.feed_data(chunk)?;
|
||||||
Ok((chunk, decoder))
|
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;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
return Ok(Async::Ready(Some(chunk)));
|
return Ok(Async::Ready(Some(chunk)));
|
||||||
@ -103,14 +113,10 @@ where
|
|||||||
}
|
}
|
||||||
Async::Ready(None) => {
|
Async::Ready(None) => {
|
||||||
self.eof = true;
|
self.eof = true;
|
||||||
if let Some(mut decoder) = self.decoder.take() {
|
return if let Some(mut decoder) = self.decoder.take() {
|
||||||
self.fut = Some(run(move || {
|
Ok(Async::Ready(decoder.feed_eof()?))
|
||||||
let chunk = decoder.feed_eof()?;
|
|
||||||
Ok((chunk, decoder))
|
|
||||||
}));
|
|
||||||
continue;
|
|
||||||
} else {
|
} else {
|
||||||
return Ok(Async::Ready(None));
|
Ok(Async::Ready(None))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Async::NotReady => break,
|
Async::NotReady => break,
|
||||||
|
Loading…
Reference in New Issue
Block a user