-
Notifications
You must be signed in to change notification settings - Fork 899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid two allocations #6326
Avoid two allocations #6326
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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))) | ||
Comment on lines
-1078
to
+1077
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, so just want to make sure I'm understanding this correctly. This avoids allocating the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, exactly. |
||
} | ||
|
||
/// Trims comment characters and possibly a single space from the left of a string. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain why you're brining
Itertools
into scope?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is used for the
Itertools::join
on line 1077.