Avoid allocating intermediate strings in ItemizedBlock::trimmed_block_as_string
This commit is contained in:
parent
40909b4331
commit
9d407bfd1b
@ -533,10 +533,11 @@ impl ItemizedBlock {
|
|||||||
|
|
||||||
/// Returns the block as a string, with each line trimmed at the start.
|
/// Returns the block as a string, with each line trimmed at the start.
|
||||||
fn trimmed_block_as_string(&self) -> String {
|
fn trimmed_block_as_string(&self) -> String {
|
||||||
self.lines
|
self.lines.iter().fold(String::new(), |mut acc, line| {
|
||||||
.iter()
|
acc.push_str(line.trim_start());
|
||||||
.map(|line| format!("{} ", line.trim_start()))
|
acc.push(' ');
|
||||||
.collect::<String>()
|
acc
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the block as a string under its original form.
|
/// Returns the block as a string under its original form.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user