Replace manual iter exhaust with for_each(drop).
This commit is contained in:
parent
178becdd7c
commit
5c58eec0bd
6 changed files with 9 additions and 13 deletions
|
@ -1260,8 +1260,7 @@ impl<K, V> IntoIterator for BTreeMap<K, V> {
|
||||||
#[stable(feature = "btree_drop", since = "1.7.0")]
|
#[stable(feature = "btree_drop", since = "1.7.0")]
|
||||||
impl<K, V> Drop for IntoIter<K, V> {
|
impl<K, V> Drop for IntoIter<K, V> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
for _ in &mut *self {
|
self.for_each(drop);
|
||||||
}
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let leaf_node = ptr::read(&self.front).into_node();
|
let leaf_node = ptr::read(&self.front).into_node();
|
||||||
if let Some(first_parent) = leaf_node.deallocate_and_ascend() {
|
if let Some(first_parent) = leaf_node.deallocate_and_ascend() {
|
||||||
|
|
|
@ -1076,7 +1076,7 @@ impl<'a, T, F> Drop for DrainFilter<'a, T, F>
|
||||||
where F: FnMut(&mut T) -> bool,
|
where F: FnMut(&mut T) -> bool,
|
||||||
{
|
{
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
for _ in self { }
|
self.for_each(drop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2354,7 +2354,7 @@ impl<'a, T> DoubleEndedIterator for Drain<'a, T> {
|
||||||
impl<'a, T> Drop for Drain<'a, T> {
|
impl<'a, T> Drop for Drain<'a, T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// exhaust self first
|
// exhaust self first
|
||||||
while let Some(_) = self.next() {}
|
self.for_each(drop);
|
||||||
|
|
||||||
if self.tail_len > 0 {
|
if self.tail_len > 0 {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -2474,9 +2474,7 @@ impl<'a, I: Iterator> ExactSizeIterator for Splice<'a, I> {}
|
||||||
#[stable(feature = "vec_splice", since = "1.21.0")]
|
#[stable(feature = "vec_splice", since = "1.21.0")]
|
||||||
impl<'a, I: Iterator> Drop for Splice<'a, I> {
|
impl<'a, I: Iterator> Drop for Splice<'a, I> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// exhaust drain first
|
self.drain.by_ref().for_each(drop);
|
||||||
while let Some(_) = self.drain.next() {}
|
|
||||||
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
if self.drain.tail_len == 0 {
|
if self.drain.tail_len == 0 {
|
||||||
|
@ -2605,8 +2603,7 @@ impl<'a, T, F> Drop for DrainFilter<'a, T, F>
|
||||||
where F: FnMut(&mut T) -> bool,
|
where F: FnMut(&mut T) -> bool,
|
||||||
{
|
{
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
for _ in self.by_ref() { }
|
self.for_each(drop);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
self.vec.set_len(self.old_len - self.del);
|
self.vec.set_len(self.old_len - self.del);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2177,7 +2177,7 @@ unsafe impl<'a, T: Send> Send for Drain<'a, T> {}
|
||||||
#[stable(feature = "drain", since = "1.6.0")]
|
#[stable(feature = "drain", since = "1.6.0")]
|
||||||
impl<'a, T: 'a> Drop for Drain<'a, T> {
|
impl<'a, T: 'a> Drop for Drain<'a, T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
for _ in self.by_ref() {}
|
self.for_each(drop);
|
||||||
|
|
||||||
let source_deque = unsafe { self.deque.as_mut() };
|
let source_deque = unsafe { self.deque.as_mut() };
|
||||||
|
|
||||||
|
|
|
@ -207,7 +207,7 @@ pub struct Iter<A: Array> {
|
||||||
|
|
||||||
impl<A: Array> Drop for Iter<A> {
|
impl<A: Array> Drop for Iter<A> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
for _ in self {}
|
self.for_each(drop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ impl<'a, A: Array> Iterator for Drain<'a, A> {
|
||||||
impl<'a, A: Array> Drop for Drain<'a, A> {
|
impl<'a, A: Array> Drop for Drain<'a, A> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// exhaust self first
|
// exhaust self first
|
||||||
while let Some(_) = self.next() {}
|
self.for_each(drop);
|
||||||
|
|
||||||
if self.tail_len > 0 {
|
if self.tail_len > 0 {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -1129,7 +1129,7 @@ impl<'a, K, V> ExactSizeIterator for Drain<'a, K, V> {
|
||||||
|
|
||||||
impl<'a, K: 'a, V: 'a> Drop for Drain<'a, K, V> {
|
impl<'a, K: 'a, V: 'a> Drop for Drain<'a, K, V> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
for _ in self {}
|
self.for_each(drop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue