mirror of
https://github.com/actix/actix-web.git
synced 2024-12-30 12:00:38 +00:00
use mem::take where possible (#1507)
This commit is contained in:
parent
201090d7a2
commit
f3b0233477
10 changed files with 20 additions and 32 deletions
|
@ -189,7 +189,7 @@ impl MessageBody for Body {
|
|||
if len == 0 {
|
||||
Poll::Ready(None)
|
||||
} else {
|
||||
Poll::Ready(Some(Ok(mem::replace(bin, Bytes::new()))))
|
||||
Poll::Ready(Some(Ok(mem::take(bin))))
|
||||
}
|
||||
}
|
||||
Body::Message(ref mut body) => Pin::new(body.as_mut()).poll_next(cx),
|
||||
|
@ -307,7 +307,7 @@ impl MessageBody for Bytes {
|
|||
if self.is_empty() {
|
||||
Poll::Ready(None)
|
||||
} else {
|
||||
Poll::Ready(Some(Ok(mem::replace(self.get_mut(), Bytes::new()))))
|
||||
Poll::Ready(Some(Ok(mem::take(self.get_mut()))))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -324,9 +324,7 @@ impl MessageBody for BytesMut {
|
|||
if self.is_empty() {
|
||||
Poll::Ready(None)
|
||||
} else {
|
||||
Poll::Ready(Some(Ok(
|
||||
mem::replace(self.get_mut(), BytesMut::new()).freeze()
|
||||
)))
|
||||
Poll::Ready(Some(Ok(mem::take(self.get_mut()).freeze())))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -344,7 +342,7 @@ impl MessageBody for &'static str {
|
|||
Poll::Ready(None)
|
||||
} else {
|
||||
Poll::Ready(Some(Ok(Bytes::from_static(
|
||||
mem::replace(self.get_mut(), "").as_ref(),
|
||||
mem::take(self.get_mut()).as_ref(),
|
||||
))))
|
||||
}
|
||||
}
|
||||
|
@ -362,10 +360,7 @@ impl MessageBody for Vec<u8> {
|
|||
if self.is_empty() {
|
||||
Poll::Ready(None)
|
||||
} else {
|
||||
Poll::Ready(Some(Ok(Bytes::from(mem::replace(
|
||||
self.get_mut(),
|
||||
Vec::new(),
|
||||
)))))
|
||||
Poll::Ready(Some(Ok(Bytes::from(mem::take(self.get_mut())))))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -383,7 +378,7 @@ impl MessageBody for String {
|
|||
Poll::Ready(None)
|
||||
} else {
|
||||
Poll::Ready(Some(Ok(Bytes::from(
|
||||
mem::replace(self.get_mut(), String::new()).into_bytes(),
|
||||
mem::take(self.get_mut()).into_bytes(),
|
||||
))))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use std::collections::HashSet;
|
||||
use std::mem::replace;
|
||||
use std::mem;
|
||||
|
||||
use time::{Duration, OffsetDateTime};
|
||||
|
||||
|
@ -273,7 +273,7 @@ impl CookieJar {
|
|||
)]
|
||||
pub fn clear(&mut self) {
|
||||
self.delta_cookies.clear();
|
||||
for delta in replace(&mut self.original_cookies, HashSet::new()) {
|
||||
for delta in mem::take(&mut self.original_cookies) {
|
||||
self.remove(delta.cookie);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ impl<B: MessageBody> MessageBody for EncoderBody<B> {
|
|||
if b.is_empty() {
|
||||
Poll::Ready(None)
|
||||
} else {
|
||||
Poll::Ready(Some(Ok(std::mem::replace(b, Bytes::new()))))
|
||||
Poll::Ready(Some(Ok(std::mem::take(b))))
|
||||
}
|
||||
}
|
||||
EncoderBody::Stream(b) => b.poll_next(cx),
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
// Because MSRV is 1.39.0.
|
||||
#![allow(clippy::mem_replace_with_default)]
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
|
@ -795,13 +792,10 @@ where
|
|||
let inner_p = inner.as_mut().project();
|
||||
let mut parts = FramedParts::with_read_buf(
|
||||
inner_p.io.take().unwrap(),
|
||||
std::mem::replace(inner_p.codec, Codec::default()),
|
||||
std::mem::replace(inner_p.read_buf, BytesMut::default()),
|
||||
);
|
||||
parts.write_buf = std::mem::replace(
|
||||
inner_p.write_buf,
|
||||
BytesMut::default(),
|
||||
std::mem::take(inner_p.codec),
|
||||
std::mem::take(inner_p.read_buf),
|
||||
);
|
||||
parts.write_buf = std::mem::take(inner_p.write_buf);
|
||||
let framed = Framed::from_parts(parts);
|
||||
let upgrade =
|
||||
inner_p.upgrade.take().unwrap().call((req, framed));
|
||||
|
|
|
@ -200,8 +200,7 @@ impl Session {
|
|||
.extensions()
|
||||
.get::<Rc<RefCell<SessionInner>>>()
|
||||
{
|
||||
let state =
|
||||
std::mem::replace(&mut s_impl.borrow_mut().state, HashMap::new());
|
||||
let state = std::mem::take(&mut s_impl.borrow_mut().state);
|
||||
(s_impl.borrow().status.clone(), Some(state.into_iter()))
|
||||
} else {
|
||||
(SessionStatus::Unchanged, None)
|
||||
|
|
|
@ -12,7 +12,7 @@ use actix_service::{fn_service, Service, ServiceFactory};
|
|||
use futures::future::{join_all, ok, FutureExt, LocalBoxFuture};
|
||||
|
||||
use crate::config::{AppConfig, AppService};
|
||||
use crate::data::{FnDataFactory, DataFactory};
|
||||
use crate::data::{DataFactory, FnDataFactory};
|
||||
use crate::error::Error;
|
||||
use crate::guard::Guard;
|
||||
use crate::request::{HttpRequest, HttpRequestPool};
|
||||
|
@ -76,7 +76,7 @@ where
|
|||
let mut config = AppService::new(config, default.clone(), self.data.clone());
|
||||
|
||||
// register services
|
||||
std::mem::replace(&mut *self.services.borrow_mut(), Vec::new())
|
||||
std::mem::take(&mut *self.services.borrow_mut())
|
||||
.into_iter()
|
||||
.for_each(|mut srv| srv.register(&mut config));
|
||||
|
||||
|
@ -99,7 +99,7 @@ where
|
|||
});
|
||||
|
||||
// external resources
|
||||
for mut rdef in std::mem::replace(&mut *self.external.borrow_mut(), Vec::new()) {
|
||||
for mut rdef in std::mem::take(&mut *self.external.borrow_mut()) {
|
||||
rmap.add(&mut rdef, None);
|
||||
}
|
||||
|
||||
|
|
|
@ -379,7 +379,7 @@ where
|
|||
let guards = if self.guards.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(std::mem::replace(&mut self.guards, Vec::new()))
|
||||
Some(std::mem::take(&mut self.guards))
|
||||
};
|
||||
let mut rdef = if config.is_root() || !self.rdef.is_empty() {
|
||||
ResourceDef::new(insert_slash(self.rdef.clone()))
|
||||
|
|
|
@ -56,7 +56,7 @@ impl Route {
|
|||
}
|
||||
|
||||
pub(crate) fn take_guards(&mut self) -> Vec<Box<dyn Guard>> {
|
||||
std::mem::replace(Rc::get_mut(&mut self.guards).unwrap(), Vec::new())
|
||||
std::mem::take(Rc::get_mut(&mut self.guards).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -429,7 +429,7 @@ where
|
|||
let mut rmap = ResourceMap::new(ResourceDef::root_prefix(&self.rdef));
|
||||
|
||||
// external resources
|
||||
for mut rdef in std::mem::replace(&mut self.external, Vec::new()) {
|
||||
for mut rdef in std::mem::take(&mut self.external) {
|
||||
rmap.add(&mut rdef, None);
|
||||
}
|
||||
|
||||
|
|
|
@ -515,7 +515,7 @@ where
|
|||
let guards = if self.guards.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(std::mem::replace(&mut self.guards, Vec::new()))
|
||||
Some(std::mem::take(&mut self.guards))
|
||||
};
|
||||
|
||||
let mut rdef = if config.is_root() || !self.rdef.is_empty() {
|
||||
|
|
Loading…
Reference in a new issue