Skip to content

Commit 159c525

Browse files
committed
Auto merge of #188 - mbrubeck:iter, r=Amanieu
Implement FusedIterator and size_hint for DrainFilter None
2 parents 17e6ecc + 82a5065 commit 159c525

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

src/map.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ where
846846
Some(item) => unsafe {
847847
let &(ref key, ref value) = item.as_ref();
848848
Some((key, value))
849-
}
849+
},
850850
None => None,
851851
}
852852
}
@@ -886,7 +886,7 @@ where
886886
Some(item) => unsafe {
887887
let &mut (ref key, ref mut value) = item.as_mut();
888888
Some((key, value))
889-
}
889+
},
890890
None => None,
891891
}
892892
}
@@ -1390,8 +1390,15 @@ where
13901390
fn next(&mut self) -> Option<Self::Item> {
13911391
self.inner.next(&mut self.f)
13921392
}
1393+
1394+
#[inline]
1395+
fn size_hint(&self) -> (usize, Option<usize>) {
1396+
(0, self.inner.iter.size_hint().1)
1397+
}
13931398
}
13941399

1400+
impl<K, V, F> FusedIterator for DrainFilter<'_, K, V, F> where F: FnMut(&K, &mut V) -> bool {}
1401+
13951402
/// Portions of `DrainFilter` shared with `set::DrainFilter`
13961403
pub(super) struct DrainFilterInner<'a, K, V> {
13971404
pub iter: RawIter<(K, V)>,
@@ -1585,7 +1592,7 @@ impl<'a, K, V, S> RawEntryBuilder<'a, K, V, S> {
15851592
Some(item) => unsafe {
15861593
let &(ref key, ref value) = item.as_ref();
15871594
Some((key, value))
1588-
}
1595+
},
15891596
None => None,
15901597
}
15911598
}
@@ -2055,7 +2062,7 @@ impl<'a, K, V> Iterator for Iter<'a, K, V> {
20552062
Some(x) => unsafe {
20562063
let r = x.as_ref();
20572064
Some((&r.0, &r.1))
2058-
}
2065+
},
20592066
None => None,
20602067
}
20612068
}
@@ -2083,7 +2090,7 @@ impl<'a, K, V> Iterator for IterMut<'a, K, V> {
20832090
Some(x) => unsafe {
20842091
let r = x.as_mut();
20852092
Some((&r.0, &mut r.1))
2086-
}
2093+
},
20872094
None => None,
20882095
}
20892096
}

src/raw/mod.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ impl<T> RawTable<T> {
406406
// Avoid `Option::ok_or_else` because it bloats LLVM IR.
407407
let (layout, ctrl_offset) = match calculate_layout::<T>(buckets) {
408408
Some(lco) => lco,
409-
None => return Err(fallability.capacity_overflow())
409+
None => return Err(fallability.capacity_overflow()),
410410
};
411411
let ptr = match NonNull::new(alloc(layout)) {
412412
Some(ptr) => ptr,
@@ -688,7 +688,10 @@ impl<T> RawTable<T> {
688688
*self = Self::with_capacity(min_size)
689689
} else {
690690
// Avoid `Result::unwrap_or_else` because it bloats LLVM IR.
691-
if self.resize(min_size, hasher, Fallibility::Infallible).is_err() {
691+
if self
692+
.resize(min_size, hasher, Fallibility::Infallible)
693+
.is_err()
694+
{
692695
unsafe { hint::unreachable_unchecked() }
693696
}
694697
}
@@ -701,7 +704,10 @@ impl<T> RawTable<T> {
701704
pub fn reserve(&mut self, additional: usize, hasher: impl Fn(&T) -> u64) {
702705
if additional > self.growth_left {
703706
// Avoid `Result::unwrap_or_else` because it bloats LLVM IR.
704-
if self.reserve_rehash(additional, hasher, Fallibility::Infallible).is_err() {
707+
if self
708+
.reserve_rehash(additional, hasher, Fallibility::Infallible)
709+
.is_err()
710+
{
705711
unsafe { hint::unreachable_unchecked() }
706712
}
707713
}
@@ -1114,7 +1120,7 @@ impl<T: Clone> Clone for RawTable<T> {
11141120
match Self::new_uninitialized(self.buckets(), Fallibility::Infallible) {
11151121
Ok(table) => table,
11161122
Err(_) => hint::unreachable_unchecked(),
1117-
}
1123+
},
11181124
);
11191125

11201126
new_table.clone_from_spec(self, |new_table| {
@@ -1151,7 +1157,7 @@ impl<T: Clone> Clone for RawTable<T> {
11511157
match Self::new_uninitialized(source.buckets(), Fallibility::Infallible) {
11521158
Ok(table) => table,
11531159
Err(_) => hint::unreachable_unchecked(),
1154-
}
1160+
},
11551161
);
11561162
}
11571163

src/set.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,8 +1462,15 @@ where
14621462
let (k, _) = self.inner.next(&mut |k, _| f(k))?;
14631463
Some(k)
14641464
}
1465+
1466+
#[inline]
1467+
fn size_hint(&self) -> (usize, Option<usize>) {
1468+
(0, self.inner.iter.size_hint().1)
1469+
}
14651470
}
14661471

1472+
impl<K, F> FusedIterator for DrainFilter<'_, K, F> where F: FnMut(&K) -> bool {}
1473+
14671474
impl<T, S> Clone for Intersection<'_, T, S> {
14681475
#[cfg_attr(feature = "inline-more", inline)]
14691476
fn clone(&self) -> Self {

0 commit comments

Comments
 (0)