mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
125ca8672e
## Summary With `"sort_order": "extension"`, `compare_rel_paths_by` compared extensions with `to_lowercase()`, which allocates two `String`s for each pair of file names it compares. `compare_lowercase` compares ASCII strings by their lowercased bytes and falls back to `to_lowercase()` otherwise. For ASCII, `to_lowercase()` only lowercases each byte, so the order is unchanged. The project panel sorts its visible entries with this comparator, on a background thread, each time it rebuilds them. `cargo bench -p project_panel --bench sorting`, which sorts 96k entries from a Linux checkout, in extension order: | Sort mode | Before | After | |---|---|---| | `DirectoriesFirst` | 39.7 ms | 14.7 ms | | `Mixed` | 38.6 ms | 12.4 ms | | `FilesFirst` | 35.4 ms | 11.6 ms | The other sort orders don't run this code. They measured 1 to 3% faster, as did Unicode order, which this change can't affect, so that difference is noise. ## Testing - `cargo test -p util --lib paths` passes. - `cargo test -p project_panel` passes. - `./script/clippy -p util` passes. - Outside Zed, `compare_lowercase` matched `a.to_lowercase().cmp(&b.to_lowercase())` on 6 million random pairs of ASCII and non-ASCII strings, and on every pair of the 252 extensions in the benchmark snapshot. ## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [x] UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). - [x] Tests cover the new or changed behavior. Release Notes: - N/A