From 008b3df97d430f12d0b7dbdebacc048d1aa0666f Mon Sep 17 00:00:00 2001 From: Mattias Wallin Date: Sat, 14 Sep 2024 19:56:35 +0200 Subject: [PATCH] Avoid allocating `Vec` in `light_rewrite_comment` --- src/comment.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/comment.rs b/src/comment.rs index 1b3b88d68a5..b7d7a396a67 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -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}; @@ -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 @@ -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.