Skip to content

Commit

Permalink
Remove allocation caused by str::repeat()
Browse files Browse the repository at this point in the history
  • Loading branch information
cdesaintguilhem committed Oct 6, 2024
1 parent f60efcc commit 7fa0177
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/indent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ pub fn apply_indent(
let n_indent_chars = usize::try_from(indent.visual * args.tab).expect("Both `indent.visual` and `args.tab` should be non-negative integers");
let mut new_line =
String::with_capacity(trimmed_line.len() + n_indent_chars);
new_line.insert_str(0, &indent_char.repeat(n_indent_chars));
for idx in 0..n_indent_chars {
new_line.insert_str(idx, indent_char);
}
new_line.insert_str(n_indent_chars, trimmed_line);
new_line
} else {
Expand Down

0 comments on commit 7fa0177

Please sign in to comment.