diff options
| author | Mattias Wallin <mattias@klingawallin.se> | 2024-09-14 19:56:35 +0200 |
|---|---|---|
| committer | Yacin Tmimi <yacintmimi@gmail.com> | 2024-09-17 12:42:33 -0400 |
| commit | 008b3df97d430f12d0b7dbdebacc048d1aa0666f (patch) | |
| tree | b0391a5ac8141dd74ecdbf36d43c428e89618ea6 | |
| parent | 019578f924e7c70a26262bd882e442dd8faa5299 (diff) | |
| download | rust-008b3df97d430f12d0b7dbdebacc048d1aa0666f.tar.gz rust-008b3df97d430f12d0b7dbdebacc048d1aa0666f.zip | |
Avoid allocating `Vec` in `light_rewrite_comment`
| -rw-r--r-- | src/comment.rs | 8 |
1 files 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. |
