From 4712015e61c5ce6b90d4c86c75dc5ad1b786a568 Mon Sep 17 00:00:00 2001 From: Krysztal112233 Date: Mon, 18 Mar 2024 12:04:02 +0800 Subject: [PATCH 1/2] tr: lazily generate the character mapping as necessary --- src/uu/tr/src/operation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/tr/src/operation.rs b/src/uu/tr/src/operation.rs index cfc9b11cb9..14561b1dee 100644 --- a/src/uu/tr/src/operation.rs +++ b/src/uu/tr/src/operation.rs @@ -129,11 +129,11 @@ impl Sequence { truncate_set1_flag: bool, ) -> Result<(Vec, Vec), BadSequence> { let set1 = Self::from_str(set1_str)?; - let set2 = Self::from_str(set2_str)?; let is_char_star = |s: &&Self| -> bool { matches!(s, Self::CharStar(_)) }; let set1_star_count = set1.iter().filter(is_char_star).count(); if set1_star_count == 0 { + let set2 = Self::from_str(set2_str)?; let set2_star_count = set2.iter().filter(is_char_star).count(); if set2_star_count < 2 { let char_star = set2.iter().find_map(|s| match s { From 05731d13af386a5d9c1586a35f0432a41aedefb4 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Mon, 18 Mar 2024 13:56:49 +0100 Subject: [PATCH 2/2] tr: remove fixed todo --- src/uu/tr/src/operation.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/uu/tr/src/operation.rs b/src/uu/tr/src/operation.rs index 14561b1dee..77ace6b40d 100644 --- a/src/uu/tr/src/operation.rs +++ b/src/uu/tr/src/operation.rs @@ -122,7 +122,6 @@ impl Sequence { } // Hide all the nasty sh*t in here - // TODO: Make the 2 set lazily generate the character mapping as necessary. pub fn solve_set_characters( set1_str: &[u8], set2_str: &[u8],