Skip to content

Commit 9d407bf

Browse files
Mattias Wallinytmimi
Mattias Wallin
authored andcommitted
Avoid allocating intermediate strings in ItemizedBlock::trimmed_block_as_string
1 parent 40909b4 commit 9d407bf

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Diff for: src/comment.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,11 @@ impl ItemizedBlock {
533533

534534
/// Returns the block as a string, with each line trimmed at the start.
535535
fn trimmed_block_as_string(&self) -> String {
536-
self.lines
537-
.iter()
538-
.map(|line| format!("{} ", line.trim_start()))
539-
.collect::<String>()
536+
self.lines.iter().fold(String::new(), |mut acc, line| {
537+
acc.push_str(line.trim_start());
538+
acc.push(' ');
539+
acc
540+
})
540541
}
541542

542543
/// Returns the block as a string under its original form.

0 commit comments

Comments
 (0)