Repository: sxyazi/yazi
File: yazi-core/src/mgr/watcher.rs (Rust)

Code before:
		let handler = move |res: Result<notify::Event, notify::Error>| {
			let Ok(event) = res else { return };
			if event.kind.is_access() {
				return;
			}
			Self::push_files_impl(&out_tx_, event.paths.into_iter().map(Url::from));
		};

		let config = notify::Config::default().with_poll_interval(Duration::from_millis(500));
		if yazi_adapter::WSL.get() || cfg!(target_os = "netbsd") {
			tokio::spawn(Self::fan_in(in_rx, PollWatcher::new(handler, config).unwrap()));
		} else {
			tokio::spawn(Self::fan_in(in_rx, RecommendedWatcher::new(handler, config).unwrap()));
		}

		#[cfg(any(target_os = "linux", target_os = "macos"))]
		yazi_fs::mounts::Partitions::monitor(yazi_fs::mounts::PARTITIONS.clone(), || {
			yazi_macro::err!(yazi_dds::Pubsub::pub_from_mount())
		});

		tokio::spawn(Self::fan_out(out_rx));
		Self { in_tx, out_tx }
	}

	pub(super) fn watch<'a>(&mut self, it: impl Iterator<Item = &'a Url>) {
		self.in_tx.send(it.into_iter().filter(|u| u.is_regular()).cloned().collect()).ok();
	}

	pub(super) fn push_files(&self, urls: Vec<Url>) {
		Self::push_files_impl(&self.out_tx, urls.into_iter());
	}

	fn push_files_impl(out_tx: &mpsc::UnboundedSender<Url>, urls: impl Iterator<Item = Url>) {
		let (mut parents, watched) = (HashSet::new(), WATCHED.read());
		for u in urls {
			let Some(p) = u.parent_url() else { continue };
			if !watched.contains(&p) && !LINKED.read().from_dir(&p).any(|u| watched.contains(u)) {
				continue;
			}
			out_tx.send(u).ok();
			if !parents.contains(&p) {
				out_tx.send(p.clone()).ok();
				parents.insert(p);
			}
		}
	}

	// TODO: performance improvement
	pub(super) fn trigger_dirs(&self, folders: &[&Folder]) {
		let todo: Vec<_> =
			folders.iter().filter(|&f| f.url.is_regular()).map(|&f| (f.url.to_owned(), f.cha)).collect();

Review comment (suggestion):
Calling `into_iter()` on an `Iterator` is redundant; you can directly call `.filter(...)` on `it` to improve clarity.
```suggestion
		self.in_tx.send(it.filter(|u| u.is_regular()).cloned().collect()).ok();
```

Code after:
		let handler = move |res: Result<notify::Event, notify::Error>| {
			let Ok(event) = res else { return };
			if event.kind.is_access() {
				return;
			}
			Self::push_files_impl(&out_tx_, event.paths.into_iter().map(Url::from));
		};

		let config = notify::Config::default().with_poll_interval(Duration::from_millis(500));
		if yazi_adapter::WSL.get() || cfg!(target_os = "netbsd") {
			tokio::spawn(Self::fan_in(in_rx, PollWatcher::new(handler, config).unwrap()));
		} else {
			tokio::spawn(Self::fan_in(in_rx, RecommendedWatcher::new(handler, config).unwrap()));
		}

		#[cfg(any(target_os = "linux", target_os = "macos"))]
		yazi_fs::mounts::Partitions::monitor(yazi_fs::mounts::PARTITIONS.clone(), || {
			yazi_macro::err!(yazi_dds::Pubsub::pub_from_mount())
		});

		tokio::spawn(Self::fan_out(out_rx));
		Self { in_tx, out_tx }
	}

	pub(super) fn watch<'a>(&mut self, it: impl Iterator<Item = &'a Url>) {
		self.in_tx.send(it.filter(|u| u.is_regular()).cloned().collect()).ok();
	}

	pub(super) fn push_files(&self, urls: Vec<Url>) {
		Self::push_files_impl(&self.out_tx, urls.into_iter());
	}

	fn push_files_impl(out_tx: &mpsc::UnboundedSender<Url>, urls: impl Iterator<Item = Url>) {
		let (mut parents, watched) = (HashSet::new(), WATCHED.read());
		for u in urls {
			let Some(p) = u.parent_url() else { continue };
			if !watched.contains(&p) && !LINKED.read().from_dir(&p).any(|u| watched.contains(u)) {
				continue;
			}
			out_tx.send(u).ok();
			if !parents.contains(&p) {
				out_tx.send(p.clone()).ok();
				parents.insert(p);
			}
		}
	}

	// TODO: performance improvement
	pub(super) fn trigger_dirs(&self, folders: &[&Folder]) {
		let todo: Vec<_> =
			folders.iter().filter(|&f| f.url.is_regular()).map(|&f| (f.url.to_owned(), f.cha)).collect();