Skip to content

Commit 19c7200

Browse files
committed
rm: improve is_dir_empty from O(n) to O(1)
1 parent bd2e33b commit 19c7200

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

src/uu/rm/src/rm.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,7 @@ pub fn remove(files: &[&OsStr], options: &Options) -> bool {
373373
/// `path` must be a directory. If there is an error reading the
374374
/// contents of the directory, this returns `false`.
375375
fn is_dir_empty(path: &Path) -> bool {
376-
match fs::read_dir(path) {
377-
Err(_) => false,
378-
Ok(iter) => iter.count() == 0,
379-
}
376+
fs::read_dir(path).is_ok_and(|mut iter| iter.next().is_none())
380377
}
381378

382379
#[cfg(unix)]

0 commit comments

Comments
 (0)