Skip to content

Commit f4361bc

Browse files
committed
Improve Set Difference size_hint
This implementation isn't perfect, but it is spec compliant as far as I can tell
1 parent f540cb7 commit f4361bc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/set.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,6 +1851,7 @@ where
18511851
let (_, upper) = self.iter.size_hint();
18521852
(0, upper)
18531853
}
1854+
18541855
#[cfg_attr(feature = "inline-more", inline)]
18551856
fn fold<B, F>(self, init: B, mut f: F) -> B
18561857
where
@@ -1916,9 +1917,10 @@ where
19161917

19171918
#[cfg_attr(feature = "inline-more", inline)]
19181919
fn size_hint(&self) -> (usize, Option<usize>) {
1919-
let (_, upper) = self.iter.size_hint();
1920-
(0, upper)
1920+
let (lower, upper) = self.iter.size_hint();
1921+
(lower.saturating_sub(self.other.len()), upper)
19211922
}
1923+
19221924
#[cfg_attr(feature = "inline-more", inline)]
19231925
fn fold<B, F>(self, init: B, mut f: F) -> B
19241926
where
@@ -1975,10 +1977,12 @@ where
19751977
fn next(&mut self) -> Option<&'a T> {
19761978
self.iter.next()
19771979
}
1980+
19781981
#[cfg_attr(feature = "inline-more", inline)]
19791982
fn size_hint(&self) -> (usize, Option<usize>) {
19801983
self.iter.size_hint()
19811984
}
1985+
19821986
#[cfg_attr(feature = "inline-more", inline)]
19831987
fn fold<B, F>(self, init: B, f: F) -> B
19841988
where
@@ -2048,10 +2052,12 @@ where
20482052
fn next(&mut self) -> Option<&'a T> {
20492053
self.iter.next()
20502054
}
2055+
20512056
#[cfg_attr(feature = "inline-more", inline)]
20522057
fn size_hint(&self) -> (usize, Option<usize>) {
20532058
self.iter.size_hint()
20542059
}
2060+
20552061
#[cfg_attr(feature = "inline-more", inline)]
20562062
fn fold<B, F>(self, init: B, f: F) -> B
20572063
where

0 commit comments

Comments
 (0)