Skip to content

Commit b53292d

Browse files
committed
perf(linter): use unstable sort where possible (#13818)
Noticed that some places can use unstable sort but was using stable sort.
1 parent c96f7e9 commit b53292d

12 files changed

+20
-20
lines changed

crates/oxc_linter/src/config/config_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ impl ConfigStoreBuilder {
482482
let new_rules = self
483483
.rules
484484
.iter()
485-
.sorted_by_key(|(r, _)| (r.plugin_name(), r.name()))
485+
.sorted_unstable_by_key(|(r, _)| (r.plugin_name(), r.name()))
486486
.map(|(r, severity)| ESLintRule {
487487
plugin_name: r.plugin_name().to_string(),
488488
rule_name: r.name().to_string(),

crates/oxc_linter/src/config/ignore_matcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl LintIgnoreMatcher {
2727
};
2828

2929
// Sort nested configs deepest-to-shallowest for correct precedence
30-
nested.sort_by(|a, b| {
30+
nested.sort_unstable_by(|a, b| {
3131
let a_len = a.1.components().count();
3232
let b_len = b.1.components().count();
3333
b_len.cmp(&a_len)

crates/oxc_linter/src/rules/eslint/sort_keys.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ fn alphanumeric_sort(arr: &mut [String]) {
202202
}
203203

204204
fn natural_sort(arr: &mut [String]) {
205-
arr.sort_by(|a, b| {
205+
arr.sort_unstable_by(|a, b| {
206206
let mut a_chars = a.chars();
207207
let mut b_chars = b.chars();
208208

crates/oxc_linter/src/rules/jest/consistent_test_it.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl Rule for ConsistentTestIt {
206206
fn run_once(&self, ctx: &LintContext) {
207207
let mut describe_nesting_hash: FxHashMap<ScopeId, i32> = FxHashMap::default();
208208
let mut possible_jest_nodes = collect_possible_jest_call_node(ctx);
209-
possible_jest_nodes.sort_by_key(|n| n.node.id());
209+
possible_jest_nodes.sort_unstable_by_key(|n| n.node.id());
210210

211211
for possible_jest_node in &possible_jest_nodes {
212212
self.run(&mut describe_nesting_hash, possible_jest_node, ctx);

crates/oxc_linter/src/rules/jest/max_nested_describe.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl Rule for MaxNestedDescribe {
135135
fn run_once(&self, ctx: &LintContext) {
136136
let mut describes_hooks_depth: Vec<ScopeId> = vec![];
137137
let mut possibles_jest_nodes = collect_possible_jest_call_node(ctx);
138-
possibles_jest_nodes.sort_by_key(|n| n.node.id());
138+
possibles_jest_nodes.sort_unstable_by_key(|n| n.node.id());
139139

140140
for possible_jest_node in &possibles_jest_nodes {
141141
self.run(possible_jest_node, &mut describes_hooks_depth, ctx);
@@ -421,7 +421,7 @@ fn test() {
421421
describe('another suite', () => {
422422
describe('another suite', () => {
423423
describe('another suite', () => {
424-
424+
425425
})
426426
})
427427
})
@@ -440,7 +440,7 @@ fn test() {
440440
describe('another suite', () => {
441441
describe('another suite', () => {
442442
describe('another suite', () => {
443-
443+
444444
})
445445
})
446446
})

crates/oxc_linter/src/rules/jest/no_duplicate_hooks.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Rule for NoDuplicateHooks {
112112
hook_contexts.insert(NodeId::ROOT, Vec::new());
113113

114114
let mut possibles_jest_nodes = collect_possible_jest_call_node(ctx);
115-
possibles_jest_nodes.sort_by_key(|n| n.node.id());
115+
possibles_jest_nodes.sort_unstable_by_key(|n| n.node.id());
116116

117117
for possible_jest_node in possibles_jest_nodes {
118118
Self::run(&possible_jest_node, NodeId::ROOT, &mut hook_contexts, ctx);
@@ -580,7 +580,7 @@ fn test() {
580580
beforeEach(() => {})
581581
afterEach(() => {})
582582
afterAll(() => {})
583-
583+
584584
test("bar", () => {
585585
someFn();
586586
})
@@ -705,7 +705,7 @@ fn test() {
705705
describe.each(['hello'])('%s', () => {
706706
beforeEach(() => {});
707707
beforeEach(() => {});
708-
708+
709709
it('is not fine', () => {});
710710
});
711711
",
@@ -716,14 +716,14 @@ fn test() {
716716
describe('something', () => {
717717
describe.each(['hello'])('%s', () => {
718718
beforeEach(() => {});
719-
719+
720720
it('is fine', () => {});
721721
});
722-
722+
723723
describe.each(['world'])('%s', () => {
724724
beforeEach(() => {});
725725
beforeEach(() => {});
726-
726+
727727
it('is not fine', () => {});
728728
});
729729
});

crates/oxc_linter/src/rules/jest/no_identical_title.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl Rule for NoIdenticalTitle {
104104
})
105105
.collect::<Vec<(Span, JestFnKind, NodeId)>>();
106106
// After being sorted by parent_id, the span with the same parent will be placed nearby.
107-
kind_and_spans.sort_by(|a, b| a.2.cmp(&b.2));
107+
kind_and_spans.sort_unstable_by(|a, b| a.2.cmp(&b.2));
108108

109109
// Skip the first element, for `describe('foo'); describe('foo');`, we only need to check the second one.
110110
for i in 1..kind_and_spans.len() {

crates/oxc_linter/src/rules/jest/prefer_hooks_on_top.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl Rule for PreferHooksOnTop {
153153
fn run_once(&self, ctx: &LintContext) {
154154
let mut hooks_contexts: FxHashMap<ScopeId, bool> = FxHashMap::default();
155155
let mut possibles_jest_nodes = collect_possible_jest_call_node(ctx);
156-
possibles_jest_nodes.sort_by_key(|n| n.node.id());
156+
possibles_jest_nodes.sort_unstable_by_key(|n| n.node.id());
157157

158158
for possible_jest_node in &possibles_jest_nodes {
159159
Self::run(possible_jest_node, &mut hooks_contexts, ctx);

crates/oxc_linter/src/rules/jest/require_top_level_describe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl Rule for RequireTopLevelDescribe {
132132
fn run_once(&self, ctx: &LintContext) {
133133
let mut describe_contexts: FxHashMap<ScopeId, usize> = FxHashMap::default();
134134
let mut possibles_jest_nodes = collect_possible_jest_call_node(ctx);
135-
possibles_jest_nodes.sort_by_key(|n| n.node.id());
135+
possibles_jest_nodes.sort_unstable_by_key(|n| n.node.id());
136136

137137
for possible_jest_node in &possibles_jest_nodes {
138138
self.run(possible_jest_node, &mut describe_contexts, ctx);

crates/oxc_linter/src/rules/react/style_prop_object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl Rule for StylePropObject {
153153
})
154154
.unwrap_or_default();
155155

156-
allow.sort();
156+
allow.sort_unstable();
157157

158158
Self(Box::new(StylePropObjectConfig { allow }))
159159
}

0 commit comments

Comments
 (0)