mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
perf: RuleTable::any_enabled
(#10971)
This commit is contained in:
parent
f779babc5f
commit
d4e140d47f
2 changed files with 16 additions and 1 deletions
|
@ -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
|
||||||
|
|
|
@ -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.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue