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 drop_len = iter.len();
|
||||||
|
|
||||||
let mut vec = self.vec;
|
let mut vec = self.vec;
|
||||||
|
@ -685,7 +685,7 @@ where
|
|||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
self.finished = true;
|
self.finished = true;
|
||||||
Some(mem::replace(&mut self.v, &mut []))
|
Some(mem::take(&mut self.v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -749,7 +749,7 @@ where
|
|||||||
match idx_opt {
|
match idx_opt {
|
||||||
None => self.finish(),
|
None => self.finish(),
|
||||||
Some(idx) => {
|
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);
|
let (head, tail) = tmp.split_at_mut(idx);
|
||||||
self.v = head;
|
self.v = head;
|
||||||
Some(&mut tail[1..])
|
Some(&mut tail[1..])
|
||||||
@ -830,7 +830,7 @@ where
|
|||||||
if idx == self.v.len() {
|
if idx == self.v.len() {
|
||||||
self.finished = true;
|
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);
|
let (head, tail) = tmp.split_at_mut(idx);
|
||||||
self.v = tail;
|
self.v = tail;
|
||||||
Some(head)
|
Some(head)
|
||||||
@ -876,7 +876,7 @@ where
|
|||||||
if idx == 0 {
|
if idx == 0 {
|
||||||
self.finished = true;
|
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);
|
let (head, tail) = tmp.split_at_mut(idx);
|
||||||
self.v = head;
|
self.v = head;
|
||||||
Some(tail)
|
Some(tail)
|
||||||
|
@ -348,7 +348,7 @@ impl Write for &mut [u8] {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
|
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
|
||||||
let amt = cmp::min(data.len(), self.len());
|
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]);
|
a.copy_from_slice(&data[..amt]);
|
||||||
*self = b;
|
*self = b;
|
||||||
Ok(amt)
|
Ok(amt)
|
||||||
|
@ -253,7 +253,7 @@ mod tests;
|
|||||||
|
|
||||||
use crate::cmp;
|
use crate::cmp;
|
||||||
use crate::fmt;
|
use crate::fmt;
|
||||||
use crate::mem::replace;
|
use crate::mem::take;
|
||||||
use crate::ops::{Deref, DerefMut};
|
use crate::ops::{Deref, DerefMut};
|
||||||
use crate::slice;
|
use crate::slice;
|
||||||
use crate::str;
|
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() {
|
if bufs.is_empty() {
|
||||||
assert!(n == accumulated_len, "advancing io slices beyond their length");
|
assert!(n == accumulated_len, "advancing io slices beyond their length");
|
||||||
} else {
|
} else {
|
||||||
@ -1329,7 +1329,7 @@ impl<'a> IoSlice<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*bufs = &mut replace(bufs, &mut [])[remove..];
|
*bufs = &mut take(bufs)[remove..];
|
||||||
if bufs.is_empty() {
|
if bufs.is_empty() {
|
||||||
assert!(n == accumulated_len, "advancing io slices beyond their length");
|
assert!(n == accumulated_len, "advancing io slices beyond their length");
|
||||||
} else {
|
} else {
|
||||||
|
@ -30,7 +30,7 @@ impl<'a> IoSliceMut<'a> {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn advance(&mut self, n: usize) {
|
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);
|
let (_, remaining) = slice.split_at_mut(n);
|
||||||
self.0 = remaining;
|
self.0 = remaining;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user