Skip to content

Commit fcbe59d

Browse files
bors[bot]Amanieu
andcommitted
Merge #61 #62
61: Improve worst-case performance of HashSet.is_subset r=Amanieu a=Amanieu Ported from rust-lang/rust#59665 62: Remove incorrect debug_assert r=Amanieu a=Amanieu Fixes #60 Co-authored-by: Amanieu d'Antras <[email protected]>
3 parents 9068eb7 + 9f558f5 + 7225250 commit fcbe59d

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/external_trait_impls/rayon/set.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,11 @@ where
256256
///
257257
/// This method runs in a potentially parallel fashion.
258258
pub fn par_is_subset(&self, other: &Self) -> bool {
259-
self.into_par_iter().all(|x| other.contains(x))
259+
if self.len() <= other.len() {
260+
self.into_par_iter().all(|x| other.contains(x))
261+
} else {
262+
false
263+
}
260264
}
261265

262266
/// Returns `true` if the set is a superset of another,

src/raw/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,8 @@ fn special_is_empty(ctrl: u8) -> bool {
118118
#[inline]
119119
#[allow(clippy::cast_possible_truncation)]
120120
fn h1(hash: u64) -> usize {
121-
#[cfg(target_pointer_width = "32")]
122-
{
123-
debug_assert!(hash <= u64::from(u32::max_value()));
124-
}
125-
hash as usize // truncation
121+
// On 32-bit platforms we simply ignore the higher hash bits.
122+
hash as usize
126123
}
127124

128125
/// Secondary hash function, saved in the low 7 bits of the control byte.

src/set.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,11 @@ where
640640
/// assert_eq!(set.is_subset(&sup), false);
641641
/// ```
642642
pub fn is_subset(&self, other: &Self) -> bool {
643-
self.iter().all(|v| other.contains(v))
643+
if self.len() <= other.len() {
644+
self.iter().all(|v| other.contains(v))
645+
} else {
646+
false
647+
}
644648
}
645649

646650
/// Returns `true` if the set is a superset of another,

0 commit comments

Comments
 (0)