Skip to content

Commit 2c14518

Browse files
committed
Compute digits vec only once
1 parent ed011c4 commit 2c14518

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

clippy_lints/src/literal_representation.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,19 @@ impl<'a> DigitInfo<'a> {
193193
self.suffix.unwrap_or("")
194194
)
195195
} else {
196-
let mut hint = self.digits
196+
let filtered_digits_vec = self.digits
197197
.chars()
198-
.rev()
199198
.filter(|&c| c != '_')
200-
.collect::<Vec<_>>()
199+
.rev()
200+
.collect::<Vec<_>>();
201+
let mut hint = filtered_digits_vec
201202
.chunks(group_size)
202203
.map(|chunk| chunk.into_iter().rev().collect())
203204
.rev()
204205
.collect::<Vec<String>>()
205206
.join("_");
206207
// Forces hexadecimal values to be grouped by 4 being filled with zeroes (e.g 0x00ab_cdef)
207-
let nb_digits_to_fill = self.digits.chars().filter(|&c| c != '_').collect::<Vec<_>>().len() % 4;
208+
let nb_digits_to_fill = filtered_digits_vec.len() % 4;
208209
if self.radix == Radix::Hexadecimal && nb_digits_to_fill != 0 {
209210
hint = format!("{:0>4}{}", &hint[..nb_digits_to_fill], &hint[nb_digits_to_fill..]);
210211
}

0 commit comments

Comments
 (0)