Merge pull request #8384 from cakebaker/rm_improve_is_dir_empty

rm: improve `is_dir_empty` from O(n) to O(1)
This commit is contained in:
Dorian Péron
2025-07-24 15:37:07 +02:00
committed by GitHub
+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)]