From 946275dd1f5b0e9af6ad137255e6170deeea61a7 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Fri, 30 Aug 2019 16:44:10 -0700 Subject: [PATCH] perf(body): re-enable optimization for full-data Bodies --- src/body/mod.rs | 21 +++++---------------- src/body/payload.rs | 1 - src/proto/h2/server.rs | 3 +-- src/server/tcp.rs | 2 +- 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/body/mod.rs b/src/body/mod.rs index 0f7350f0..4372ec43 100644 --- a/src/body/mod.rs +++ b/src/body/mod.rs @@ -35,6 +35,11 @@ pub(crate) fn take_full_data(body: &mut T) -> Option() .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::>() .expect("must be T::Data") @@ -44,22 +49,6 @@ pub(crate) fn take_full_data(body: &mut T) -> Option(pub(crate) Option); -} - fn _assert_send_sync() { fn _assert_send() {} fn _assert_sync() {} diff --git a/src/body/payload.rs b/src/body/payload.rs index 88c2d741..86fa385e 100644 --- a/src/body/payload.rs +++ b/src/body/payload.rs @@ -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`. diff --git a/src/proto/h2/server.rs b/src/proto/h2/server.rs index 702073c1..39e1f514 100644 --- a/src/proto/h2/server.rs +++ b/src/proto/h2/server.rs @@ -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); diff --git a/src/server/tcp.rs b/src/server/tcp.rs index c07a3bf3..de02b547 100644 --- a/src/server/tcp.rs +++ b/src/server/tcp.rs @@ -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 _;