optimize actix-http messages

This commit is contained in:
fakeshadow 2021-01-18 08:58:22 +08:00
parent ee10148444
commit 9a3ba6d04c
1 changed files with 8 additions and 14 deletions

View File

@ -353,14 +353,6 @@ impl<T: Head> Message<T> {
} }
} }
impl<T: Head> Clone for Message<T> {
fn clone(&self) -> Self {
Message {
head: self.head.clone(),
}
}
}
impl<T: Head> std::ops::Deref for Message<T> { impl<T: Head> std::ops::Deref for Message<T> {
type Target = T; type Target = T;
@ -377,11 +369,9 @@ impl<T: Head> std::ops::DerefMut for Message<T> {
impl<T: Head> Drop for Message<T> { impl<T: Head> Drop for Message<T> {
fn drop(&mut self) { fn drop(&mut self) {
if Rc::strong_count(&self.head) == 1 {
T::with_pool(|p| p.release(self.head.clone())) T::with_pool(|p| p.release(self.head.clone()))
} }
} }
}
pub(crate) struct BoxedResponseHead { pub(crate) struct BoxedResponseHead {
head: Option<Box<ResponseHead>>, head: Option<Box<ResponseHead>>,
@ -416,9 +406,13 @@ impl std::ops::DerefMut for BoxedResponseHead {
impl Drop for BoxedResponseHead { impl Drop for BoxedResponseHead {
fn drop(&mut self) { fn drop(&mut self) {
if let Some(head) = self.head.take() { RESPONSE_POOL.with(move |p| {
RESPONSE_POOL.with(move |p| p.release(head)) p.release(
} self.head
.take()
.expect("ResponseHead is taken before dropped"),
)
})
} }
} }