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

Use generic Content in Text to avoid reallocation in fill_text #2360

Merged
merged 1 commit into from
Apr 1, 2024

Conversation

hecrj
Copy link
Member

@hecrj hecrj commented Apr 1, 2024

Renderer::fill_text asks for a &str just to turn it into a String... Amazing.

Let's get rid of that, shall we?

@@ -526,7 +526,7 @@ where

renderer.fill_text(
Text {
content: &option.to_string(),
content: option.to_string(),
Copy link
Member Author

@hecrj hecrj Apr 1, 2024

Choose a reason for hiding this comment

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

No more (&option.to_string()).to_string()! I will sleep tight tonight.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey, since you're looking into this .to_string reallocations couldn't the text helper function avoid reallocation as well here:
Text::new(text.to_string())
I always tend to use Text::new(&self.some_str) instead of text(&self.some_str) because of this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not if we want to keep the ToString compatibility (e.g. text(10)). Specialization hasn't landed yet in Rust.

Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't think of that. I guess I can always make my own helper! 😄

@hecrj hecrj enabled auto-merge April 1, 2024 09:40
@hecrj hecrj merged commit 14ed71e into master Apr 1, 2024
24 checks passed
@hecrj hecrj deleted the avoid-fill-text-allocation branch April 1, 2024 09:42
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.

2 participants