Skip to content

Commit

Permalink
refactor: Avoid unnecessary Map indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
not-my-profile authored and charliermarsh committed Jan 22, 2023
1 parent aedee72 commit 16d2ceb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ruff_macros/src/rule_code_prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ pub fn expand<'a>(
// Build up a map from prefix to matching RuleCodes.
let mut prefix_to_codes: BTreeMap<String, BTreeSet<String>> = BTreeMap::default();

let mut all_codes = BTreeSet::new();

for variant in variants {
let code_str = variant.to_string();
let code_prefix_len = code_str
Expand All @@ -107,12 +109,11 @@ pub fn expand<'a>(
.or_default()
.insert(code_str.clone());
}
prefix_to_codes
.entry(ALL.to_string())
.or_default()
.insert(code_str.clone());
all_codes.insert(code_str);
}

prefix_to_codes.insert(ALL.to_string(), all_codes);

// Add any prefix aliases (e.g., "U" to "UP").
for (alias, rule_code) in PREFIX_REDIRECTS.iter() {
prefix_to_codes.insert(
Expand Down

0 comments on commit 16d2ceb

Please sign in to comment.