Skip to content
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

Merged
merged 2 commits into from
Sep 17, 2024
Merged

Avoid two allocations #6326

merged 2 commits into from
Sep 17, 2024

Conversation

Rawk
Copy link
Contributor

@Rawk Rawk commented Sep 15, 2024

No description provided.

@@ -2,7 +2,7 @@

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

use itertools::{MultiPeek, multipeek};
use itertools::{Itertools as _, MultiPeek, multipeek};
Copy link
Contributor

@ytmimi ytmimi Sep 16, 2024

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?

Copy link
Contributor Author

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.

Comment on lines -1078 to +1077
.collect();
lines.join(&format!("\n{}", offset.to_string(config)))
.join(&format!("\n{}", offset.to_string(config)))
Copy link
Contributor

Choose a reason for hiding this comment

The 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 Vec<&str> and directly allocates into a String?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly.

@ytmimi ytmimi merged commit b552eb9 into rust-lang:master Sep 17, 2024
26 checks passed
@Rawk Rawk deleted the avoid-allocs-2 branch September 18, 2024 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants