From dbc47c9122b5731a11a5e1dc388efd0a13d65754 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Sun, 7 Feb 2021 12:19:10 -0800 Subject: [PATCH] optimize actix-http messages (#1914) --- actix-http/src/message.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/actix-http/src/message.rs b/actix-http/src/message.rs index bccb4d53e..736f35ee1 100644 --- a/actix-http/src/message.rs +++ b/actix-http/src/message.rs @@ -343,6 +343,8 @@ impl ResponseHead { } pub struct Message { + // Rc here should not be cloned by anyone. + // It's used to reuse allocation of T and no shared ownership is allowed. head: Rc, } @@ -353,14 +355,6 @@ impl Message { } } -impl Clone for Message { - fn clone(&self) -> Self { - Message { - head: self.head.clone(), - } - } -} - impl std::ops::Deref for Message { type Target = T; @@ -377,9 +371,7 @@ impl std::ops::DerefMut for Message { impl Drop for Message { 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())) } }