1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-01-19 06:04:40 +01:00

optimize message pool release (#1871)

This commit is contained in:
fakeshadow 2021-01-04 21:03:46 +08:00 committed by GitHub
parent 7d632d0b7b
commit e567873326
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,7 +67,7 @@ impl Head for RequestHead {
fn clear(&mut self) { fn clear(&mut self) {
self.flags = Flags::empty(); self.flags = Flags::empty();
self.headers.clear(); self.headers.clear();
self.extensions.borrow_mut().clear(); self.extensions.get_mut().clear();
} }
fn pool() -> &'static MessagePool<Self> { fn pool() -> &'static MessagePool<Self> {
@ -440,9 +440,11 @@ impl<T: Head> MessagePool<T> {
#[inline] #[inline]
fn get_message(&'static self) -> Message<T> { fn get_message(&'static self) -> Message<T> {
if let Some(mut msg) = self.0.borrow_mut().pop() { if let Some(mut msg) = self.0.borrow_mut().pop() {
if let Some(r) = Rc::get_mut(&mut msg) { // Message is put in pool only when it's the last copy.
r.clear(); // which means it's guaranteed to be unique when popped out.
} Rc::get_mut(&mut msg)
.expect("Multiple copies exist")
.clear();
Message { head: msg } Message { head: msg }
} else { } else {
Message { Message {