Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit f46c0fc

Browse files
committed
Don't box MainContext::invoke() closure twice
1 parent ac1a38e commit f46c0fc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/main_context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl MainContext {
4040
pub fn invoke_with_priority<F>(&self, priority: Priority, func: F)
4141
where F: FnOnce() + Send + 'static {
4242
unsafe {
43-
let func = Box::into_raw(Box::new(Some(Box::new(func))));
43+
let func = Box::into_raw(Box::new(Some(func)));
4444
glib_ffi::g_main_context_invoke_full(self.to_glib_none().0, priority.to_glib(), Some(trampoline::<F>),
4545
func as gpointer, Some(destroy_closure::<F>))
4646
}
@@ -64,14 +64,14 @@ impl MainContext {
6464

6565
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
6666
unsafe extern "C" fn trampoline<F: FnOnce() + Send + 'static>(func: gpointer) -> gboolean {
67-
let func: &mut Option<Box<F>> = transmute(func);
67+
let func: &mut Option<F> = transmute(func);
6868
let func = func.take().expect("MainContext::invoke() closure called multiple times");
6969
func();
7070
glib_ffi::G_SOURCE_REMOVE
7171
}
7272

7373
unsafe extern "C" fn destroy_closure<F: FnOnce() + Send + 'static>(ptr: gpointer) {
74-
Box::<Option<Box<F>>>::from_raw(ptr as *mut _);
74+
Box::<Option<F>>::from_raw(ptr as *mut _);
7575
}
7676

7777

0 commit comments

Comments
 (0)