Skip to content

Commit c87bcc4

Browse files
authored
Remove unnecessary allocation in RepaintCause::new (#4146)
Hi! I'm using egui for the UI of a VST3/Clap plugin, and this kind of environment is rather picky on performance. I use [assert_no_alloc](https://crates.io/crates/assert_no_alloc) to make sure the audio thread is never allocating. The audio thread may request a repaint of the GUI tho, and this is where a saw that it may allocate when tracing the repaint reason. Turns out it's not necessary, `Location::caller` is `'static`, so using a `&'static str` instead of a `String` in `RepaintCause::file` will just work, so this PR just does that.
1 parent efc0a63 commit c87bcc4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

crates/egui/src/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ struct ViewportState {
256256
#[derive(Clone, Debug)]
257257
pub struct RepaintCause {
258258
/// What file had the call that requested the repaint?
259-
pub file: String,
259+
pub file: &'static str,
260260

261261
/// What line number of the the call that requested the repaint?
262262
pub line: u32,
@@ -269,7 +269,7 @@ impl RepaintCause {
269269
pub fn new() -> Self {
270270
let caller = Location::caller();
271271
Self {
272-
file: caller.file().to_owned(),
272+
file: caller.file(),
273273
line: caller.line(),
274274
}
275275
}

0 commit comments

Comments
 (0)