rm: improve is_dir_empty from O(n) to O(1)

This commit is contained in:
Daniel Hofstetter
2025-07-24 11:10:00 +02:00
parent bd2e33bb34
commit 19c7200d34
+1 -4
View File
@@ -373,10 +373,7 @@ pub fn remove(files: &[&OsStr], options: &Options) -> bool {
/// `path` must be a directory. If there is an error reading the
/// contents of the directory, this returns `false`.
fn is_dir_empty(path: &Path) -> bool {
match fs::read_dir(path) {
Err(_) => false,
Ok(iter) => iter.count() == 0,
}
fs::read_dir(path).is_ok_and(|mut iter| iter.next().is_none())
}
#[cfg(unix)]