Skip to content

Commit

Permalink
chore: Avoid duplicate box on constructing BoxBody (#2009)
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto authored Oct 25, 2024
1 parent d61a55f commit eaa81dd
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tonic/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ where
B: http_body::Body<Data = bytes::Bytes> + Send + 'static,
B::Error: Into<crate::BoxError>,
{
body.map_err(crate::Status::map_error).boxed_unsync()
let mut body = Some(body);
if let Some(body) = <dyn std::any::Any>::downcast_mut::<Option<BoxBody>>(&mut body) {
body.take().unwrap()
} else {
body.unwrap()
.map_err(crate::Status::map_error)
.boxed_unsync()
}
}

/// Create an empty `BoxBody`
Expand Down

0 comments on commit eaa81dd

Please sign in to comment.