perf: replace .count() from iterators to more performative operations

This commit is contained in:
Talison Fabio 2025-04-07 21:15:22 -03:00 committed by João Marcos
parent 61dab2af29
commit c6cbf6e157
4 changed files with 4 additions and 4 deletions

View File

@ -18,7 +18,7 @@ pub fn unpack_archive(
password: Option<&[u8]>,
quiet: bool,
) -> crate::Result<usize> {
assert!(output_folder.read_dir().expect("dir exists").count() == 0);
assert!(output_folder.read_dir().expect("dir exists").next().is_none());
let archive = match password {
Some(password) => Archive::with_password(archive_path, password),

View File

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

View File

@ -37,7 +37,7 @@ pub fn unpack_archive<R>(
where
R: Read + Seek,
{
assert!(output_folder.read_dir().expect("dir exists").count() == 0);
assert!(output_folder.read_dir().expect("dir exists").next().is_none());
let mut unpacked_files = 0;

View File

@ -356,7 +356,7 @@ fn smart_unpack(
let files = unpack_fn(temp_dir_path)?;
let root_contains_only_one_element = fs::read_dir(temp_dir_path)?.count() == 1;
let root_contains_only_one_element = fs::read_dir(temp_dir_path)?.take(2).count() == 1;
let (previous_path, mut new_path) = if root_contains_only_one_element {
// Only one file in the root directory, so we can just move it to the output directory