1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-02-07 13:54:24 +01:00

optimize actix-http messages (#1914)

This commit is contained in:
fakeshadow 2021-02-07 12:19:10 -08:00 committed by GitHub
parent 4c243cbf89
commit dbc47c9122
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -343,6 +343,8 @@ impl ResponseHead {
} }
pub struct Message<T: Head> { pub struct Message<T: Head> {
// Rc here should not be cloned by anyone.
// It's used to reuse allocation of T and no shared ownership is allowed.
head: Rc<T>, head: Rc<T>,
} }
@ -353,14 +355,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 +371,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>>,