Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

fuzzy_nucleo: Remove `util` dependency (#61929)

Lukas Wirthc9d1d0ddfec3
diff --git a/Cargo.lock b/Cargo.lock
index 83ae5ecc828..33d5a4920ba 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -7167,8 +7167,9 @@ dependencies = [
"criterion",
"fuzzy",
"gpui",
+ "gpui_util",
"nucleo",
- "util",
+ "path",
]
[[package]]
diff --git a/crates/fuzzy_nucleo/Cargo.toml b/crates/fuzzy_nucleo/Cargo.toml
index 2f9a1b9ec39..4ca74860b46 100644
--- a/crates/fuzzy_nucleo/Cargo.toml
+++ b/crates/fuzzy_nucleo/Cargo.toml
@@ -16,12 +16,12 @@ doctest = false
fuzzy.workspace = true
nucleo.workspace = true
gpui.workspace = true
-util.workspace = true
+gpui_util.workspace = true
+path.workspace = true
[dev-dependencies]
criterion.workspace = true
gpui = { workspace = true, features = ["test-support"] }
-util = { workspace = true, features = ["test-support"] }
[[bench]]
name = "match_benchmark"
diff --git a/crates/fuzzy_nucleo/benches/match_benchmark.rs b/crates/fuzzy_nucleo/benches/match_benchmark.rs
index ec1607a2bd6..da74af15f5a 100644
--- a/crates/fuzzy_nucleo/benches/match_benchmark.rs
+++ b/crates/fuzzy_nucleo/benches/match_benchmark.rs
@@ -1,7 +1,7 @@
use criterion::{BatchSize, BenchmarkId, Criterion, criterion_group, criterion_main};
use fuzzy::CharBag;
+use path::{PathStyle, rel_path::RelPath};
use std::sync::atomic::AtomicBool;
-use util::{paths::PathStyle, rel_path::RelPath};
const DIRS: &[&str] = &[
"src",
diff --git a/crates/fuzzy_nucleo/src/paths.rs b/crates/fuzzy_nucleo/src/paths.rs
index 037acbc37f0..b0a0fa5e475 100644
--- a/crates/fuzzy_nucleo/src/paths.rs
+++ b/crates/fuzzy_nucleo/src/paths.rs
@@ -1,4 +1,5 @@
use gpui::BackgroundExecutor;
+use path::{PathStyle, rel_path::RelPath};
use std::{
cmp::Ordering,
sync::{
@@ -6,7 +7,6 @@ use std::{
atomic::{self, AtomicBool},
},
};
-use util::{paths::PathStyle, rel_path::RelPath};
use nucleo::Utf32Str;
use nucleo::pattern::Pattern;
@@ -256,7 +256,7 @@ pub fn match_fixed_path_set(
&AtomicBool::new(false),
)
.ok();
- util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a));
+ gpui_util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a));
matcher::return_matcher(matcher);
results
}
@@ -351,6 +351,6 @@ pub async fn match_path_sets<'a, Set: PathMatchCandidateSet<'a>>(
}
let mut results = segment_results.concat();
- util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a));
+ gpui_util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a));
results
}
diff --git a/crates/fuzzy_nucleo/src/strings.rs b/crates/fuzzy_nucleo/src/strings.rs
index 81b377b598b..2486afb7ce0 100644
--- a/crates/fuzzy_nucleo/src/strings.rs
+++ b/crates/fuzzy_nucleo/src/strings.rs
@@ -161,7 +161,7 @@ where
}
let mut results = segment_results.concat();
- util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a));
+ gpui_util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a));
results
}
@@ -198,7 +198,7 @@ where
.ok();
matcher::return_matcher(matcher);
- util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a));
+ gpui_util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a));
results
}
diff --git a/crates/gpui_util/src/lib.rs b/crates/gpui_util/src/lib.rs
index fe6a3cfca66..94b0f5609f0 100644
--- a/crates/gpui_util/src/lib.rs
+++ b/crates/gpui_util/src/lib.rs
@@ -578,3 +578,25 @@ fn type_id_hasher() {
verify_hashing_with(TypeId::of::<&str>());
verify_hashing_with(TypeId::of::<Vec<u8>>());
}
+
+pub fn truncate_to_bottom_n_sorted_by<T, F>(items: &mut Vec<T>, limit: usize, compare: &F)
+where
+ F: Fn(&T, &T) -> std::cmp::Ordering,
+{
+ if limit == 0 {
+ items.truncate(0);
+ }
+ if items.len() <= limit {
+ items.sort_by(compare);
+ return;
+ }
+ // When limit is near to items.len() it may be more efficient to sort the whole list and
+ // truncate, rather than always doing selection first as is done below. It's hard to analyze
+ // where the threshold for this should be since the quickselect style algorithm used by
+ // `select_nth_unstable_by` makes the prefix partially sorted, and so its work is not wasted -
+ // the expected number of comparisons needed by `sort_by` is less than it is for some arbitrary
+ // unsorted input.
+ items.select_nth_unstable_by(limit, compare);
+ items.truncate(limit);
+ items.sort_by(compare);
+}
diff --git a/crates/util/src/util.rs b/crates/util/src/util.rs
index f86feca073f..f21ed6e046b 100644
--- a/crates/util/src/util.rs
+++ b/crates/util/src/util.rs
@@ -210,28 +210,6 @@ where
}
}
-pub fn truncate_to_bottom_n_sorted_by<T, F>(items: &mut Vec<T>, limit: usize, compare: &F)
-where
- F: Fn(&T, &T) -> Ordering,
-{
- if limit == 0 {
- items.truncate(0);
- }
- if items.len() <= limit {
- items.sort_by(compare);
- return;
- }
- // When limit is near to items.len() it may be more efficient to sort the whole list and
- // truncate, rather than always doing selection first as is done below. It's hard to analyze
- // where the threshold for this should be since the quickselect style algorithm used by
- // `select_nth_unstable_by` makes the prefix partially sorted, and so its work is not wasted -
- // the expected number of comparisons needed by `sort_by` is less than it is for some arbitrary
- // unsorted input.
- items.select_nth_unstable_by(limit, compare);
- items.truncate(limit);
- items.sort_by(compare);
-}
-
/// Prevents execution of the application with root privileges on Unix systems.
///
/// This function checks if the current process is running with root privileges