Skip to content

Commit

Permalink
Avoid allocating Vec in light_rewrite_comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawk authored and ytmimi committed Sep 17, 2024
1 parent 019578f commit 008b3df
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{borrow::Cow, iter};

use itertools::{MultiPeek, multipeek};
use itertools::{Itertools as _, MultiPeek, multipeek};
use rustc_span::Span;
use tracing::{debug, trace};

Expand Down Expand Up @@ -1056,8 +1056,7 @@ fn light_rewrite_comment(
config: &Config,
is_doc_comment: bool,
) -> String {
let lines: Vec<&str> = orig
.lines()
orig.lines()
.map(|l| {
// This is basically just l.trim(), but in the case that a line starts
// with `*` we want to leave one space before it, so it aligns with the
Expand All @@ -1075,8 +1074,7 @@ fn light_rewrite_comment(
// Preserve markdown's double-space line break syntax in doc comment.
trim_end_unless_two_whitespaces(left_trimmed, is_doc_comment)
})
.collect();
lines.join(&format!("\n{}", offset.to_string(config)))
.join(&format!("\n{}", offset.to_string(config)))
}

/// Trims comment characters and possibly a single space from the left of a string.
Expand Down

0 comments on commit 008b3df

Please sign in to comment.