From dd2ef0aad6d77368c103b4c57f28db9cafec0990 Mon Sep 17 00:00:00 2001 From: Juan Date: Fri, 8 Apr 2022 21:57:08 -0700 Subject: [PATCH] do not calculate total directory size unless it will be displayed --- src/core.rs | 3 ++- src/flags/blocks.rs | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/core.rs b/src/core.rs index 6d25b4f..629d6f9 100644 --- a/src/core.rs +++ b/src/core.rs @@ -124,7 +124,8 @@ impl Core { meta_list.push(meta); }; } - if self.flags.total_size.0 { + // Only calculate the total size of a directory if it will be displayed + if self.flags.total_size.0 && self.flags.blocks.displays_size() { for meta in &mut meta_list.iter_mut() { meta.calculate_total_size(); } diff --git a/src/flags/blocks.rs b/src/flags/blocks.rs index 3d33cac..0d34ac4 100644 --- a/src/flags/blocks.rs +++ b/src/flags/blocks.rs @@ -151,6 +151,10 @@ impl Blocks { } } + pub fn displays_size(&self) -> bool { + self.0.contains(&Block::Size) + } + /// Tnserts a [Block] of variant [INode](Block::Context), if `self` does not already contain a /// [Block] of that variant. The positioning will be best-effort approximation of coreutils /// ls position for a security context