Use unstable sorts before deduplication (#63199)

# Objective

Get some speedups by using unstable sortts.
Supersedes #58761 after rebasing onto current `main`.

## Solution

replace `.sort()` by `.unstable_sort()`.

## Testing

All tests pass in affected crates:

```
cargo test -p edit_prediction_context -p editor -p git -p language -p language_tools -p migrator
```

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- N/A
This commit is contained in:
Miguel Raz Guzmán Macedo authored and GitHub committed 2026-08-25 15:46:41 +00:00
1 parent d1074238d6
commit f9ed08004c
6 files changed
+6 -6

No files matched your search

@@ -648,7 +648,7 @@ fn identifiers_for_position(
}
}
ranges.sort_by(|a, b| a.start.cmp(&b.start).then(b.end.cmp(&a.end)));
ranges.sort_unstable_by(|a, b| a.start.cmp(&b.start).then(b.end.cmp(&a.end)));
ranges.dedup_by(|a, b| {
if a.start <= b.end {
b.start = b.start.min(a.start);
+1 -1
View File
@@ -76,7 +76,7 @@ impl Editor {
let multi_buffer_snapshot = snapshot.buffer_snapshot();
let mut selections = self.selections.all::<Point>(&snapshot.display_snapshot);
selections.sort_by_key(|s| s.head());
selections.sort_unstable_by_key(|s| s.head());
selections.dedup_by_key(|s| s.head().row);
let mut exist_targets: Vec<BookmarkTarget> = vec![];
+1 -1
View File
@@ -607,7 +607,7 @@ pub fn parse_numstat(output: &str) -> GitDiffStat {
};
entries.push((path, DiffStat { added, deleted }));
}
entries.sort_by(|(a, _), (b, _)| a.cmp(b));
entries.sort_unstable_by(|(a, _), (b, _)| a.cmp(b));
entries.dedup_by(|(a, _), (b, _)| a == b);
GitDiffStat {
+1 -1
View File
@@ -817,7 +817,7 @@ impl<'a> ChunkBrackets<'a> {
})
.collect::<Vec<_>>();
opens.sort_by_key(|r| (r.start, r.end));
opens.sort_unstable_by_key(|r| (r.start, r.end));
opens.dedup_by(|a, b| a.start == b.start && a.end == b.end);
color_pairs.sort_by_key(|(_, close, _)| close.end);
+1 -1
View File
@@ -439,7 +439,7 @@ impl LspLogView {
}),
)
.collect::<Vec<_>>();
rows.sort_by_key(|row| row.server_id);
rows.sort_unstable_by_key(|row| row.server_id);
rows.dedup_by_key(|row| row.server_id);
Some(rows)
}
+1 -1
View File
@@ -42,7 +42,7 @@ fn migrate(text: &str, patterns: MigrationPatterns, query: &Query) -> Result<Opt
}
}
edits.sort_by_key(|(range, _)| (range.start, Reverse(range.end)));
edits.sort_unstable_by_key(|(range, _)| (range.start, Reverse(range.end)));
edits.dedup_by(|(range_b, _), (range_a, _)| {
range_a.contains(&range_b.start) || range_a.contains(&range_b.end)
});