Skip to content

Commit

Permalink
Remove unnecessary String allocation
Browse files Browse the repository at this point in the history
Remove unnecessary String allocation by passing &format! or &x.to_string as impl Into<String>
  • Loading branch information
RamType0 committed Nov 1, 2021
1 parent 8a2a7f7 commit 0245f28
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -128,7 +128,7 @@ impl Counter {
)
.push(
// We show the value of the counter here
Text::new(&self.value.to_string()).size(50),
Text::new(self.value.to_string()).size(50),
)
.push(
// The decrement button. We tell it to produce a
Expand Down
2 changes: 1 addition & 1 deletion examples/scrollable/src/main.rs
Expand Up @@ -72,7 +72,7 @@ impl Sandbox for ScrollableDemo {
column.push(
Radio::new(
*option,
&format!("{:?}", option),
format!("{:?}", option),
Some(*theme),
Message::ThemeChanged,
)
Expand Down
2 changes: 1 addition & 1 deletion examples/styling/src/main.rs
Expand Up @@ -60,7 +60,7 @@ impl Sandbox for Styling {
column.push(
Radio::new(
*theme,
&format!("{:?}", theme),
format!("{:?}", theme),
Some(self.theme),
Message::ThemeChanged,
)
Expand Down
4 changes: 2 additions & 2 deletions examples/todos/src/main.rs
Expand Up @@ -374,7 +374,7 @@ impl Controls {
.spacing(20)
.align_items(Alignment::Center)
.push(
Text::new(&format!(
Text::new(format!(
"{} {} left",
tasks_left,
if tasks_left == 1 { "task" } else { "tasks" }
Expand Down Expand Up @@ -464,7 +464,7 @@ const ICONS: Font = Font::External {
};

fn icon(unicode: char) -> Text {
Text::new(&unicode.to_string())
Text::new(unicode.to_string())
.font(ICONS)
.width(Length::Units(20))
.horizontal_alignment(alignment::Horizontal::Center)
Expand Down
10 changes: 5 additions & 5 deletions examples/tour/src/main.rs
Expand Up @@ -417,7 +417,7 @@ impl<'a> Step {
StepMessage::SliderChanged,
))
.push(
Text::new(&value.to_string())
Text::new(value.to_string())
.width(Length::Fill)
.horizontal_alignment(alignment::Horizontal::Center),
)
Expand Down Expand Up @@ -464,7 +464,7 @@ impl<'a> Step {
StepMessage::SpacingChanged,
))
.push(
Text::new(&format!("{} px", spacing))
Text::new(format!("{} px", spacing))
.width(Length::Fill)
.horizontal_alignment(alignment::Horizontal::Center),
);
Expand Down Expand Up @@ -497,7 +497,7 @@ impl<'a> Step {
.spacing(20)
.push(Text::new("You can change its size:"))
.push(
Text::new(&format!("This text is {} pixels", size)).size(size),
Text::new(format!("This text is {} pixels", size)).size(size),
)
.push(Slider::new(
size_slider,
Expand All @@ -518,7 +518,7 @@ impl<'a> Step {
.padding(20)
.spacing(20)
.push(Text::new("And its color:"))
.push(Text::new(&format!("{:?}", color)).color(color))
.push(Text::new(format!("{:?}", color)).color(color))
.push(color_sliders);

Self::container("Text")
Expand Down Expand Up @@ -589,7 +589,7 @@ impl<'a> Step {
StepMessage::ImageWidthChanged,
))
.push(
Text::new(&format!("Width: {} px", width.to_string()))
Text::new(format!("Width: {} px", width.to_string()))
.width(Length::Fill)
.horizontal_alignment(alignment::Horizontal::Center),
)
Expand Down

0 comments on commit 0245f28

Please sign in to comment.