1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-27 10:30:33 +00: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> {
// 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>,
}
@ -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> {
type Target = T;
@ -377,9 +371,7 @@ impl<T: Head> std::ops::DerefMut for Message<T> {
impl<T: Head> Drop for Message<T> {
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()))
}
}