perf(body): re-enable optimization for full-data Bodies

This commit is contained in:
Sean McArthur
2019-08-30 16:44:10 -07:00
parent 3c6f7999cd
commit 946275dd1f
4 changed files with 7 additions and 20 deletions

View File

@@ -35,6 +35,11 @@ pub(crate) fn take_full_data<T: Payload + 'static>(body: &mut T) -> Option<T::Da
.downcast_mut::<Body>()
.expect("must be Body")
.take_full_data();
// This second cast is required to make the type system happy.
// Without it, the compiler cannot reason that the type is actually
// `T::Data`. Oh wells.
//
// It's still a measurable win!
(&mut full as &mut dyn Any)
.downcast_mut::<Option<T::Data>>()
.expect("must be T::Data")
@@ -44,22 +49,6 @@ pub(crate) fn take_full_data<T: Payload + 'static>(body: &mut T) -> Option<T::Da
}
}
// The full_data API is not stable, so these types are to try to prevent
// users from being able to:
//
// - Implment `__hyper_full_data` on their own Payloads.
// - Call `__hyper_full_data` on any Payload.
//
// That's because to implement it, they need to name these types, and
// they can't because they aren't exported. And to call it, they would
// need to create one of these values, which they also can't.
pub(crate) mod internal {
#[allow(missing_debug_implementations)]
pub struct FullDataArg(pub(crate) ());
#[allow(missing_debug_implementations)]
pub struct FullDataRet<B>(pub(crate) Option<B>);
}
fn _assert_send_sync() {
fn _assert_send<T: Send>() {}
fn _assert_sync<T: Sync>() {}

View File

@@ -4,7 +4,6 @@ use bytes::Buf;
use http::HeaderMap;
use crate::common::{Pin, Poll, task};
use super::internal::{FullDataArg, FullDataRet};
use http_body::{Body as HttpBody, SizeHint};
/// This trait represents a streaming body of a `Request` or `Response`.

View File

@@ -6,7 +6,6 @@ use h2::server::{Builder, Connection, Handshake, SendResponse};
use tokio_io::{AsyncRead, AsyncWrite};
use crate::body::Payload;
use crate::body::internal::FullDataArg;
use crate::common::exec::H2Exec;
use crate::common::{Future, Pin, Poll, task};
use crate::headers;
@@ -264,7 +263,7 @@ where
},
};
let (head, mut body) = res.into_parts();
let (head, body) = res.into_parts();
let mut res = ::http::Response::from_parts(head, ());
super::strip_connection_headers(res.headers_mut(), false);

View File

@@ -1,7 +1,7 @@
use std::fmt;
use std::io;
use std::net::{SocketAddr, TcpListener as StdTcpListener};
use std::time::{Duration, Instant};
use std::time::Duration;
use futures_core::Stream;
use futures_util::FutureExt as _;