Skip to content

Commit 23bec54

Browse files
mattsu2020sylvestre
authored andcommitted
refactor: replace repeat().take() with repeat_n() for better performance
Replace `std::iter::repeat().take()` patterns with `std::iter::repeat_n()` in format_modifiers.rs. This change improves performance by avoiding the overhead of the `take()` iterator adapter and directly creating an iterator that yields the exact number of elements needed.
1 parent 136b184 commit 23bec54

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/uu/date/src/format_modifiers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ fn apply_modifiers(
401401
.try_reserve(target_len)
402402
.map_err(|_| width_too_large_error())?;
403403
padded.push(sign);
404-
padded.extend(std::iter::repeat('0').take(padding));
404+
padded.extend(std::iter::repeat_n('0', padding));
405405
padded.push_str(rest);
406406
result = padded;
407407
} else {
@@ -414,7 +414,7 @@ fn apply_modifiers(
414414
padded
415415
.try_reserve(target_len)
416416
.map_err(|_| width_too_large_error())?;
417-
padded.extend(std::iter::repeat(pad_char).take(padding));
417+
padded.extend(std::iter::repeat_n(pad_char, padding));
418418
padded.push_str(&result);
419419
result = padded;
420420
}

0 commit comments

Comments
 (0)