Skip to content

Commit 2a81e96

Browse files
talis-fbmarcospb19
authored andcommitted
perf: replace .count() from iterators to more performative operations
1 parent 6981e43 commit 2a81e96

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

src/archive/rar.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn unpack_archive(
1818
password: Option<&[u8]>,
1919
quiet: bool,
2020
) -> crate::Result<usize> {
21-
assert!(output_folder.read_dir().expect("dir exists").count() == 0);
21+
assert!(output_folder.read_dir().expect("dir exists").next().is_none());
2222

2323
let archive = match password {
2424
Some(password) => Archive::with_password(archive_path, password),

src/archive/tar.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::{
2424
/// Unpacks the archive given by `archive` into the folder given by `into`.
2525
/// Assumes that output_folder is empty
2626
pub fn unpack_archive(reader: Box<dyn Read>, output_folder: &Path, quiet: bool) -> crate::Result<usize> {
27-
assert!(output_folder.read_dir().expect("dir exists").count() == 0);
27+
assert!(output_folder.read_dir().expect("dir exists").next().is_none());
2828
let mut archive = tar::Archive::new(reader);
2929

3030
let mut files_unpacked = 0;

src/archive/zip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn unpack_archive<R>(
3737
where
3838
R: Read + Seek,
3939
{
40-
assert!(output_folder.read_dir().expect("dir exists").count() == 0);
40+
assert!(output_folder.read_dir().expect("dir exists").next().is_none());
4141

4242
let mut unpacked_files = 0;
4343

src/commands/decompress.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ fn smart_unpack(
356356

357357
let files = unpack_fn(temp_dir_path)?;
358358

359-
let root_contains_only_one_element = fs::read_dir(temp_dir_path)?.count() == 1;
359+
let root_contains_only_one_element = fs::read_dir(temp_dir_path)?.take(2).count() == 1;
360360

361361
let (previous_path, mut new_path) = if root_contains_only_one_element {
362362
// Only one file in the root directory, so we can just move it to the output directory

0 commit comments

Comments
 (0)