Rollup merge of #110633 - scottmcm:more-take, r=thomcc
More `mem::take` in `library` A bunch of places were using `replace(…, &mut [])`, but that can just be `take`.
This commit is contained in:
commit
482e407a1f
@ -197,7 +197,7 @@ impl<T, A: Allocator> Drop for Drain<'_, T, A> {
|
||||
}
|
||||
}
|
||||
|
||||
let iter = mem::replace(&mut self.iter, (&mut []).iter());
|
||||
let iter = mem::take(&mut self.iter);
|
||||
let drop_len = iter.len();
|
||||
|
||||
let mut vec = self.vec;
|
||||
|
@ -685,7 +685,7 @@ where
|
||||
None
|
||||
} else {
|
||||
self.finished = true;
|
||||
Some(mem::replace(&mut self.v, &mut []))
|
||||
Some(mem::take(&mut self.v))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -749,7 +749,7 @@ where
|
||||
match idx_opt {
|
||||
None => self.finish(),
|
||||
Some(idx) => {
|
||||
let tmp = mem::replace(&mut self.v, &mut []);
|
||||
let tmp = mem::take(&mut self.v);
|
||||
let (head, tail) = tmp.split_at_mut(idx);
|
||||
self.v = head;
|
||||
Some(&mut tail[1..])
|
||||
@ -830,7 +830,7 @@ where
|
||||
if idx == self.v.len() {
|
||||
self.finished = true;
|
||||
}
|
||||
let tmp = mem::replace(&mut self.v, &mut []);
|
||||
let tmp = mem::take(&mut self.v);
|
||||
let (head, tail) = tmp.split_at_mut(idx);
|
||||
self.v = tail;
|
||||
Some(head)
|
||||
@ -876,7 +876,7 @@ where
|
||||
if idx == 0 {
|
||||
self.finished = true;
|
||||
}
|
||||
let tmp = mem::replace(&mut self.v, &mut []);
|
||||
let tmp = mem::take(&mut self.v);
|
||||
let (head, tail) = tmp.split_at_mut(idx);
|
||||
self.v = head;
|
||||
Some(tail)
|
||||
|
@ -348,7 +348,7 @@ impl Write for &mut [u8] {
|
||||
#[inline]
|
||||
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
|
||||
let amt = cmp::min(data.len(), self.len());
|
||||
let (a, b) = mem::replace(self, &mut []).split_at_mut(amt);
|
||||
let (a, b) = mem::take(self).split_at_mut(amt);
|
||||
a.copy_from_slice(&data[..amt]);
|
||||
*self = b;
|
||||
Ok(amt)
|
||||
|
@ -253,7 +253,7 @@ mod tests;
|
||||
|
||||
use crate::cmp;
|
||||
use crate::fmt;
|
||||
use crate::mem::replace;
|
||||
use crate::mem::take;
|
||||
use crate::ops::{Deref, DerefMut};
|
||||
use crate::slice;
|
||||
use crate::str;
|
||||
@ -1186,7 +1186,7 @@ impl<'a> IoSliceMut<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
*bufs = &mut replace(bufs, &mut [])[remove..];
|
||||
*bufs = &mut take(bufs)[remove..];
|
||||
if bufs.is_empty() {
|
||||
assert!(n == accumulated_len, "advancing io slices beyond their length");
|
||||
} else {
|
||||
@ -1329,7 +1329,7 @@ impl<'a> IoSlice<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
*bufs = &mut replace(bufs, &mut [])[remove..];
|
||||
*bufs = &mut take(bufs)[remove..];
|
||||
if bufs.is_empty() {
|
||||
assert!(n == accumulated_len, "advancing io slices beyond their length");
|
||||
} else {
|
||||
|
@ -30,7 +30,7 @@ impl<'a> IoSliceMut<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn advance(&mut self, n: usize) {
|
||||
let slice = mem::replace(&mut self.0, &mut []);
|
||||
let slice = mem::take(&mut self.0);
|
||||
let (_, remaining) = slice.split_at_mut(n);
|
||||
self.0 = remaining;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user