Skip to content

Commit

Permalink
refactor: use FxHashSet instead of IndexSet
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed May 23, 2024
1 parent 8e23f62 commit 0c1eddf
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 67 deletions.
88 changes: 44 additions & 44 deletions crates/biome_configuration/src/linter/rules.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions crates/biome_service/src/file_handlers/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,12 @@ fn lint(params: LintParams) -> LintResults {
.as_ref()
.map(|rules| rules.as_enabled_rules())
.unwrap_or_default()
.into_iter()
.collect::<Vec<_>>()
} else {
// Filter rule/groups according to the `--only` and `--skip` options.
// `--only` and `--skip` behave like `--include`/`--ignore`
rule_filters(&mut rules, &params.only, &params.skip)
.into_iter()
.collect()
};
let enabled_rules = enabled_rules.into_iter().collect::<Vec<_>>();

let mut filter = AnalysisFilter::from_enabled_rules(Some(enabled_rules.as_slice()));
filter.categories = params.categories;
Expand Down
12 changes: 4 additions & 8 deletions crates/biome_service/src/file_handlers/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,26 +316,22 @@ fn lint(params: LintParams) -> LintResults {
let skipped_diagnostics = diagnostic_count - diagnostics.len() as u32;

let mut rules = settings.as_rules(params.path.as_path());
let rule_filter_list = if params.only.is_empty() {
let rule_filter_list = rules
let enabled_rules = if params.only.is_empty() {
rules
.as_ref()
.map(|rules| rules.as_enabled_rules())
.unwrap_or_default()
.into_iter()
.collect::<Vec<_>>();
rule_filter_list
} else {
// Filter rule/groups according to the `--only` and `--skip` options.
// `--only` and `--skip` behave like `--include`/`--ignore`
rule_filters(&mut rules, &params.only, &params.skip)
.into_iter()
.collect()
};
let enabled_rules = enabled_rules.into_iter().collect::<Vec<_>>();

let analyzer_options = &params
.settings
.analyzer_options::<JsonLanguage>(params.path, &params.language);
let mut filter = AnalysisFilter::from_enabled_rules(Some(rule_filter_list.as_slice()));
let mut filter = AnalysisFilter::from_enabled_rules(Some(enabled_rules.as_slice()));
filter.categories = params.categories;

// Do not report unused suppression comment diagnostics if:
Expand Down
2 changes: 0 additions & 2 deletions crates/biome_service/src/file_handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,6 @@ pub(crate) fn rule_filters(
only: &[RuleSelector],
skip: &[RuleSelector],
) -> FxHashSet<RuleFilter<'static>> {
// Filter rule/groups according to the `--only` and `--skip` options.
// `--only` and `--skip` behave like `--include`/`--ignore`
let mut enabled_rules = rustc_hash::FxHashSet::<RuleFilter>::default();
let mut only_groups = rustc_hash::FxHashSet::default();
let mut skipped_groups = rustc_hash::FxHashSet::default();
Expand Down
18 changes: 9 additions & 9 deletions xtask/codegen/src/generate_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub(crate) fn generate_rules_configuration(mode: Mode) -> Result<()> {
use biome_json_analyze::options::*;
use biome_css_analyze::options::*;
use biome_rowan::TextRange;
use indexmap::IndexSet;
use rustc_hash::FxHashSet;
use serde::{Deserialize, Serialize};
#[cfg(feature = "schema")]
use schemars::JsonSchema;
Expand Down Expand Up @@ -300,9 +300,9 @@ pub(crate) fn generate_rules_configuration(mode: Mode) -> Result<()> {
/// It returns the enabled rules by default.
///
/// The enabled rules are calculated from the difference with the disabled rules.
pub fn as_enabled_rules(&self) -> IndexSet<RuleFilter<'static>> {
let mut enabled_rules = IndexSet::new();
let mut disabled_rules = IndexSet::new();
pub fn as_enabled_rules(&self) -> FxHashSet<RuleFilter<'static>> {
let mut enabled_rules = FxHashSet::default();
let mut disabled_rules = FxHashSet::default();
#( #group_as_default_rules )*

enabled_rules.difference(&disabled_rules).copied().collect()
Expand Down Expand Up @@ -564,14 +564,14 @@ fn generate_struct(group: &str, rules: &BTreeMap<&'static str, RuleMetadata>) ->
self.all.is_none()
}

pub(crate) fn get_enabled_rules(&self) -> IndexSet<RuleFilter<'static>> {
let mut index_set = IndexSet::new();
pub(crate) fn get_enabled_rules(&self) -> FxHashSet<RuleFilter<'static>> {
let mut index_set = FxHashSet::default();
#( #rule_enabled_check_line )*
index_set
}

pub(crate) fn get_disabled_rules(&self) -> IndexSet<RuleFilter<'static>> {
let mut index_set = IndexSet::new();
pub(crate) fn get_disabled_rules(&self) -> FxHashSet<RuleFilter<'static>> {
let mut index_set = FxHashSet::default();
#( #rule_disabled_check_line )*
index_set
}
Expand Down Expand Up @@ -601,7 +601,7 @@ fn generate_struct(group: &str, rules: &BTreeMap<&'static str, RuleMetadata>) ->
&self,
parent_is_all: bool,
parent_is_recommended: bool,
enabled_rules: &mut IndexSet<RuleFilter<'static>>,
enabled_rules: &mut FxHashSet<RuleFilter<'static>>,
) {
// The order of the if-else branches MATTERS!
if self.is_all_true() || self.is_all_unset() && parent_is_all {
Expand Down

0 comments on commit 0c1eddf

Please sign in to comment.