From f4361bcee301ca77469ad16e5d5b1436f4cb6934 Mon Sep 17 00:00:00 2001 From: ToMe25 Date: Fri, 7 Jun 2024 11:54:47 +0200 Subject: [PATCH] Improve Set Difference size_hint This implementation isn't perfect, but it is spec compliant as far as I can tell --- src/set.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/set.rs b/src/set.rs index bd98af7d0..d3c70dc4f 100644 --- a/src/set.rs +++ b/src/set.rs @@ -1851,6 +1851,7 @@ where let (_, upper) = self.iter.size_hint(); (0, upper) } + #[cfg_attr(feature = "inline-more", inline)] fn fold(self, init: B, mut f: F) -> B where @@ -1916,9 +1917,10 @@ where #[cfg_attr(feature = "inline-more", inline)] fn size_hint(&self) -> (usize, Option) { - let (_, upper) = self.iter.size_hint(); - (0, upper) + let (lower, upper) = self.iter.size_hint(); + (lower.saturating_sub(self.other.len()), upper) } + #[cfg_attr(feature = "inline-more", inline)] fn fold(self, init: B, mut f: F) -> B where @@ -1975,10 +1977,12 @@ where fn next(&mut self) -> Option<&'a T> { self.iter.next() } + #[cfg_attr(feature = "inline-more", inline)] fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } + #[cfg_attr(feature = "inline-more", inline)] fn fold(self, init: B, f: F) -> B where @@ -2048,10 +2052,12 @@ where fn next(&mut self) -> Option<&'a T> { self.iter.next() } + #[cfg_attr(feature = "inline-more", inline)] fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } + #[cfg_attr(feature = "inline-more", inline)] fn fold(self, init: B, f: F) -> B where