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
|
||||
|
||||
## [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
|
||||
|
@ -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"
|
||||
|
@ -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() {
|
||||
self.fut = Some(run(move || {
|
||||
if chunk.len() < INPLACE {
|
||||
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;
|
||||
} 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,
|
||||
|
Loading…
Reference in New Issue
Block a user