Avoid doing string manipulation on render for single line label (#23227)

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2025-01-16 04:15:45 -07:00 committed by GitHub
parent 8e6fc3c807
commit 972176a574
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -36,7 +36,6 @@ use crate::{prelude::*, LabelCommon, LabelLike, LabelSize, LineHeightStyle};
pub struct Label {
base: LabelLike,
label: SharedString,
single_line: bool,
}
impl Label {
@ -53,7 +52,6 @@ impl Label {
Self {
base: LabelLike::new(),
label: label.into(),
single_line: false,
}
}
}
@ -170,7 +168,7 @@ impl LabelCommon for Label {
}
fn single_line(mut self) -> Self {
self.single_line = true;
self.label = SharedString::from(self.label.replace('\n', ""));
self.base = self.base.single_line();
self
}
@ -178,11 +176,6 @@ impl LabelCommon for Label {
impl RenderOnce for Label {
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
let target_label = if self.single_line {
SharedString::from(self.label.replace('\n', ""))
} else {
self.label
};
self.base.child(target_label)
self.base.child(self.label)
}
}