mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-03 10:00:19 +00:00
perf: replace .count()
from iterators to more performative operations
This commit is contained in:
parent
61dab2af29
commit
c6cbf6e157
@ -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),
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user