1
0
Fork 0

pass Arc<Window> by reference instead of cloning

This commit is contained in:
Micah Johnston 2020-09-05 21:37:35 -05:00
parent 10d3870644
commit 0da82a4bdd
2 changed files with 7 additions and 7 deletions

View file

@ -7,7 +7,7 @@ use winapi::um::winuser::{DefWindowProcA, WM_MOUSEMOVE, WM_PAINT, WM_TIMER};
const WIN_FRAME_TIMER: usize = 4242; const WIN_FRAME_TIMER: usize = 4242;
unsafe fn handle_timer<A: AppWindow>(win: Arc<Mutex<Window<A>>>, timer_id: usize) { unsafe fn handle_timer<A: AppWindow>(win: &Arc<Mutex<Window<A>>>, timer_id: usize) {
match timer_id { match timer_id {
WIN_FRAME_TIMER => {} WIN_FRAME_TIMER => {}
_ => (), _ => (),
@ -15,7 +15,7 @@ unsafe fn handle_timer<A: AppWindow>(win: Arc<Mutex<Window<A>>>, timer_id: usize
} }
pub(crate) unsafe fn handle_message<A: AppWindow>( pub(crate) unsafe fn handle_message<A: AppWindow>(
win: Arc<Mutex<Window<A>>>, win: &Arc<Mutex<Window<A>>>,
message: UINT, message: UINT,
wparam: WPARAM, wparam: WPARAM,
lparam: LPARAM, lparam: LPARAM,

View file

@ -59,15 +59,15 @@ unsafe extern "system" fn wnd_proc<A: AppWindow>(
} }
_ => { _ => {
if !win_ptr.is_null() { if !win_ptr.is_null() {
let win_ref: Arc<Mutex<Window<A>>> = let win: Arc<Mutex<Window<A>>> =
Arc::from_raw(win_ptr as *mut Mutex<Window<A>>); Arc::from_raw(win_ptr as *mut Mutex<Window<A>>);
let win = Arc::clone(&win_ref);
let ret = handle_message(win, msg, wparam, lparam); let ret = handle_message(&win, msg, wparam, lparam);
// todo: need_reconfigure thing? // todo: need_reconfigure thing?
// If we don't do this, the Arc will be dropped and we'll get a crash. // If we don't do this, the Arc will be dropped and we'll get a crash.
let _ = Arc::into_raw(win_ref); let _ = Arc::into_raw(win);
return ret; return ret;
} }
@ -197,7 +197,7 @@ impl<A: AppWindow> Window<A> {
break; break;
} }
TranslateMessage(&mut msg); TranslateMessage(&mut msg);
handle_message(Arc::clone(&win_p), msg.message, msg.wParam, msg.lParam); handle_message(&win_p, msg.message, msg.wParam, msg.lParam);
} }
} }
} }