1
Fork 0

Avoid allocating Vec in light_rewrite_comment

This commit is contained in:
Mattias Wallin 2024-09-14 19:56:35 +02:00 committed by Yacin Tmimi
parent 019578f924
commit 008b3df97d

View file

@ -2,7 +2,7 @@
use std::{borrow::Cow, iter}; use std::{borrow::Cow, iter};
use itertools::{MultiPeek, multipeek}; use itertools::{Itertools as _, MultiPeek, multipeek};
use rustc_span::Span; use rustc_span::Span;
use tracing::{debug, trace}; use tracing::{debug, trace};
@ -1056,8 +1056,7 @@ fn light_rewrite_comment(
config: &Config, config: &Config,
is_doc_comment: bool, is_doc_comment: bool,
) -> String { ) -> String {
let lines: Vec<&str> = orig orig.lines()
.lines()
.map(|l| { .map(|l| {
// This is basically just l.trim(), but in the case that a line starts // 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 // with `*` we want to leave one space before it, so it aligns with the
@ -1075,8 +1074,7 @@ fn light_rewrite_comment(
// Preserve markdown's double-space line break syntax in doc comment. // Preserve markdown's double-space line break syntax in doc comment.
trim_end_unless_two_whitespaces(left_trimmed, is_doc_comment) trim_end_unless_two_whitespaces(left_trimmed, is_doc_comment)
}) })
.collect(); .join(&format!("\n{}", offset.to_string(config)))
lines.join(&format!("\n{}", offset.to_string(config)))
} }
/// Trims comment characters and possibly a single space from the left of a string. /// Trims comment characters and possibly a single space from the left of a string.