Skip to content

Commit

Permalink
perf(linter): replace sort_by_key with sort_unstable_by_key in fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac committed Aug 28, 2024
1 parent 139db7a commit 57756d0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions crates/oxc_linter/src/fixer/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,11 @@ impl<'a> CompositeFix<'a> {
if fixes.is_empty() {
// Do nothing
return Fix::empty();
}
if fixes.len() == 1 {
} else if fixes.len() == 1 {
return fixes.pop().unwrap();
}

fixes.sort_by(|a, b| a.span.cmp(&b.span));
fixes.sort_unstable_by(|a, b| a.span.cmp(&b.span));

// safe, as fixes.len() > 1
let start = fixes[0].span.start;
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/fixer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl<'a> Fixer<'a> {
};
}

self.messages.sort_by_key(|m| m.fix.as_ref().unwrap_or(&Fix::default()).span);
self.messages.sort_unstable_by_key(|m| m.fix.as_ref().unwrap_or(&Fix::default()).span);
let mut fixed = false;
let mut output = String::with_capacity(source_text.len());
let mut last_pos: i64 = -1;
Expand Down

0 comments on commit 57756d0

Please sign in to comment.