diff options
| author | Elisha Hollander <just4now666666@gmail.com> | 2023-10-01 13:28:19 +0300 |
|---|---|---|
| committer | donno2048 <just4now666666@gmail.com> | 2024-04-16 22:20:07 +0000 |
| commit | f275a3c65bd70c1e1f7beaf66540cc1adf1e88f2 (patch) | |
| tree | aacbfb0f15e9f32fa79501cd10471558ec9fa500 | |
| parent | ab15157960d635e4114d043b240e5a1909fb2ae4 (diff) | |
| download | rust-f275a3c65bd70c1e1f7beaf66540cc1adf1e88f2.tar.gz rust-f275a3c65bd70c1e1f7beaf66540cc1adf1e88f2.zip | |
refactor
| -rw-r--r-- | src/tools/tidy/src/style.rs | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs index 129bd260c87..b5e2c7b41d7 100644 --- a/src/tools/tidy/src/style.rs +++ b/src/tools/tidy/src/style.rs @@ -70,29 +70,32 @@ fn generate_problems<'a>( consts: &'a [u32], letter_digit: &'a HashMap<char, char>, ) -> impl Iterator<Item = u32> + 'a { - consts.into_iter().flat_map(move |const_value| { - let mut problem = format!("{:X}", const_value); - for (key, value) in letter_digit { - problem = problem.replace(&value.to_string(), &key.to_string()); - } + consts.iter().flat_map(move |const_value| { + let problem = + letter_digit.iter().fold(format!("{:X}", const_value), |acc, (key, value)| { + acc.replace(&value.to_string(), &key.to_string()) + }); let indexes: Vec<usize> = problem .chars() .enumerate() .filter_map(|(index, c)| if letter_digit.contains_key(&c) { Some(index) } else { None }) .collect(); (0..1 << indexes.len()).map(move |i| { - let result = problem - .chars() - .enumerate() - .map(|(index, c)| { - if let Some(pos) = indexes.iter().position(|&x| x == index) { - if (i >> pos) & 1 == 1 { letter_digit[&c] } else { c } - } else { - c - } - }) - .collect::<String>(); - u32::from_str_radix(&result, 0x10).unwrap() + u32::from_str_radix( + &problem + .chars() + .enumerate() + .map(|(index, c)| { + if let Some(pos) = indexes.iter().position(|&x| x == index) { + if (i >> pos) & 1 == 1 { letter_digit[&c] } else { c } + } else { + c + } + }) + .collect::<String>(), + 0x10, + ) + .unwrap() }) }) } |
