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`.