Skip to content

Commit 300530c

Browse files
chore: Eliminate extraneous allocations in the winit example (#726)
Co-authored-by: Matt Campbell <mattcampbell@pobox.com>
1 parent a55d3e1 commit 300530c

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

platforms/winit/examples/mixed_handlers.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ const ANNOUNCEMENT_DELAY: Duration = Duration::from_millis(150);
9090

9191
struct UiState {
9292
focus: NodeId,
93-
announcement: Option<String>,
94-
pending_announcement: Option<(String, Instant)>,
93+
announcement: Option<&'static str>,
94+
pending_announcement: Option<(&'static str, Instant)>,
9595
scale_factor: f64,
9696
safe_area_inset: Vec2,
9797
}
@@ -162,7 +162,7 @@ impl UiState {
162162
};
163163
// On iOS, VoiceOver announces the label of the activated button.
164164
// Postpone the live region update so the messages don't overlap.
165-
self.pending_announcement = Some((text.into(), Instant::now()));
165+
self.pending_announcement = Some((text, Instant::now()));
166166
}
167167

168168
fn flush_announcement(&mut self, adapter: &mut Adapter) -> bool {
@@ -173,9 +173,9 @@ impl UiState {
173173
return true;
174174
}
175175
if let Some((text, _)) = self.pending_announcement.take() {
176-
self.announcement = Some(text.clone());
176+
self.announcement = Some(text);
177177
adapter.update_if_active(|| {
178-
let announcement = build_announcement(&text);
178+
let announcement = build_announcement(text);
179179
let root = self.build_root();
180180
TreeUpdate {
181181
nodes: vec![(ANNOUNCEMENT_ID, announcement), (WINDOW_ID, root)],

platforms/winit/examples/simple.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ const ANNOUNCEMENT_DELAY: Duration = Duration::from_millis(150);
8686

8787
struct UiState {
8888
focus: NodeId,
89-
announcement: Option<String>,
90-
pending_announcement: Option<(String, Instant)>,
89+
announcement: Option<&'static str>,
90+
pending_announcement: Option<(&'static str, Instant)>,
9191
scale_factor: f64,
9292
inset: Vec2,
9393
}
@@ -156,7 +156,7 @@ impl UiState {
156156
};
157157
// On iOS, VoiceOver announces the label of the activated button.
158158
// Postpone the live region update so the messages don't overlap.
159-
self.pending_announcement = Some((text.into(), Instant::now()));
159+
self.pending_announcement = Some((text, Instant::now()));
160160
}
161161

162162
fn flush_announcement(&mut self, adapter: &mut Adapter) -> bool {
@@ -167,9 +167,9 @@ impl UiState {
167167
return true;
168168
}
169169
if let Some((text, _)) = self.pending_announcement.take() {
170-
self.announcement = Some(text.clone());
170+
self.announcement = Some(text);
171171
adapter.update_if_active(|| {
172-
let announcement = build_announcement(&text);
172+
let announcement = build_announcement(text);
173173
let root = self.build_root();
174174
TreeUpdate {
175175
nodes: vec![(ANNOUNCEMENT_ID, announcement), (WINDOW_ID, root)],

0 commit comments

Comments
 (0)