summaryrefslogtreecommitdiff
path: root/cli/util
diff options
context:
space:
mode:
Diffstat (limited to 'cli/util')
-rw-r--r--cli/util/collections.rs38
-rw-r--r--cli/util/file_watcher.rs3
-rw-r--r--cli/util/mod.rs1
3 files changed, 42 insertions, 0 deletions
diff --git a/cli/util/collections.rs b/cli/util/collections.rs
new file mode 100644
index 000000000..21f73024b
--- /dev/null
+++ b/cli/util/collections.rs
@@ -0,0 +1,38 @@
+// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+
+use std::marker::PhantomData;
+
+pub struct CheckedSet<T: std::hash::Hash + ?Sized> {
+ _kind: PhantomData<T>,
+ checked: std::collections::HashSet<u64>,
+}
+
+impl<T: std::hash::Hash + ?Sized> Default for CheckedSet<T> {
+ fn default() -> Self {
+ Self {
+ _kind: Default::default(),
+ checked: Default::default(),
+ }
+ }
+}
+
+impl<T: std::hash::Hash + ?Sized> CheckedSet<T> {
+ pub fn with_capacity(capacity: usize) -> Self {
+ Self {
+ _kind: PhantomData,
+ checked: std::collections::HashSet::with_capacity(capacity),
+ }
+ }
+
+ pub fn insert(&mut self, value: &T) -> bool {
+ self.checked.insert(self.get_hash(value))
+ }
+
+ fn get_hash(&self, value: &T) -> u64 {
+ use std::collections::hash_map::DefaultHasher;
+ use std::hash::Hasher;
+ let mut hasher = DefaultHasher::new();
+ value.hash(&mut hasher);
+ hasher.finish()
+ }
+}
diff --git a/cli/util/file_watcher.rs b/cli/util/file_watcher.rs
index b2628760b..176ca43f0 100644
--- a/cli/util/file_watcher.rs
+++ b/cli/util/file_watcher.rs
@@ -163,6 +163,9 @@ pub struct WatcherCommunicator {
impl WatcherCommunicator {
pub fn watch_paths(&self, paths: Vec<PathBuf>) -> Result<(), AnyError> {
+ if paths.is_empty() {
+ return Ok(());
+ }
self.paths_to_watch_tx.send(paths).map_err(AnyError::from)
}
diff --git a/cli/util/mod.rs b/cli/util/mod.rs
index 89df7bb98..69cdc77c3 100644
--- a/cli/util/mod.rs
+++ b/cli/util/mod.rs
@@ -2,6 +2,7 @@
// Note: Only add code in this folder that has no application specific logic
pub mod checksum;
+pub mod collections;
pub mod console;
pub mod diff;
pub mod display;