perf: RuleTable::any_enabled (#10971)

This commit is contained in:
Micha Reiser 2024-04-16 14:20:27 +02:00 committed by GitHub
parent f779babc5f
commit d4e140d47f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View file

@ -234,6 +234,7 @@ impl RuleSet {
/// assert!(set.contains(Rule::AmbiguousFunctionName)); /// assert!(set.contains(Rule::AmbiguousFunctionName));
/// assert!(!set.contains(Rule::BreakOutsideLoop)); /// assert!(!set.contains(Rule::BreakOutsideLoop));
/// ``` /// ```
#[inline]
pub const fn contains(&self, rule: Rule) -> bool { pub const fn contains(&self, rule: Rule) -> bool {
let rule = rule as u16; let rule = rule as u16;
let index = rule as usize / Self::SLICE_BITS as usize; let index = rule as usize / Self::SLICE_BITS as usize;
@ -243,6 +244,20 @@ impl RuleSet {
self.0[index] & mask != 0 self.0[index] & mask != 0
} }
/// Returns `true` if any of the rules in `rules` are in this set.
#[inline]
pub const fn any(&self, rules: &[Rule]) -> bool {
let mut any = false;
let mut i = 0;
while i < rules.len() {
any |= self.contains(rules[i]);
i += 1;
}
any
}
/// Returns an iterator over the rules in this set. /// Returns an iterator over the rules in this set.
/// ///
/// ## Examples /// ## Examples

View file

@ -31,7 +31,7 @@ impl RuleTable {
/// Returns whether any of the given rules should be checked. /// Returns whether any of the given rules should be checked.
#[inline] #[inline]
pub const fn any_enabled(&self, rules: &[Rule]) -> bool { pub const fn any_enabled(&self, rules: &[Rule]) -> bool {
self.enabled.intersects(&RuleSet::from_rules(rules)) self.enabled.any(rules)
} }
/// Returns whether violations of the given rule should be fixed. /// Returns whether violations of the given rule should be fixed.