From 74db5fb5f0c9aca75c52685f3e5a8bcf22d24d47 Mon Sep 17 00:00:00 2001 From: Kaur Kuut Date: Sat, 9 May 2020 16:00:49 +0300 Subject: [PATCH] Optimize clippy trivially_copy_pass_by_ref for 64-bit. --- CHANGELOG.md | 2 ++ clippy.toml | 5 +++++ druid-shell/src/platform/windows/dialog.rs | 4 ++-- druid/examples/blocking_function.rs | 2 +- druid/examples/multiwin.rs | 8 ++++---- druid/src/app_delegate.rs | 2 +- druid/src/win_handler.rs | 4 ++-- 7 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 clippy.toml diff --git a/CHANGELOG.md b/CHANGELOG.md index 2517846e4c..97820c38a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ While some features like the clipboard, menus or file dialogs are not yet availa - Global `Application` associated functions are instance methods instead, e.g. `Application::global().quit()` instead of the old `Application::quit()`. ([#763] by [@xStrom]) - Timer events will only be delivered to the widgets that requested them. ([#831] by [@sjoshid]) - `Event::Wheel` now contains a `MouseEvent` structure. ([#895] by [@teddemunnik]) +- `AppDelegate::command` now receives a `Target` instead of a `&Target`. ([#909] by [@xStrom]) ### Deprecated @@ -153,6 +154,7 @@ While some features like the clipboard, menus or file dialogs are not yet availa [#897]: https://github.com/xi-editor/druid/pull/897 [#898]: https://github.com/xi-editor/druid/pull/898 [#900]: https://github.com/xi-editor/druid/pull/900 +[#909]: https://github.com/xi-editor/druid/pull/909 ## [0.5.0] - 2020-04-01 diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 0000000000..a32f1b6e00 --- /dev/null +++ b/clippy.toml @@ -0,0 +1,5 @@ +# The default clippy value for this is 8 bytes, which is chosen to improve performance on 32-bit. +# Given that druid is being designed for the future and already even mobile phones have 64-bit CPUs, +# it makes sense to optimize for 64-bit and accept the performance hits on 32-bit. +# 16 bytes is the number of bytes that fits into two 64-bit CPU registers. +trivial-copy-size-limit = 16 \ No newline at end of file diff --git a/druid-shell/src/platform/windows/dialog.rs b/druid-shell/src/platform/windows/dialog.rs index cac083526c..b250f39606 100644 --- a/druid-shell/src/platform/windows/dialog.rs +++ b/druid-shell/src/platform/windows/dialog.rs @@ -59,7 +59,7 @@ unsafe fn make_wstrs(spec: &FileSpec) -> (Vec, Vec) { let exts = spec .extensions .iter() - .map(normalize_extension) + .map(|s| normalize_extension(*s)) .collect::>(); let name = format!("{} ({})", spec.name, exts.as_slice().join("; ")).to_wide(); let extensions = exts.as_slice().join(";").to_wide(); @@ -67,7 +67,7 @@ unsafe fn make_wstrs(spec: &FileSpec) -> (Vec, Vec) { } /// add preceding *., trimming preceding *. that might've been included by the user. -fn normalize_extension(ext: &&str) -> String { +fn normalize_extension(ext: &str) -> String { format!("*.{}", ext.trim_start_matches('*').trim_start_matches('.')) } diff --git a/druid/examples/blocking_function.rs b/druid/examples/blocking_function.rs index cc650dc906..0caa288dc5 100644 --- a/druid/examples/blocking_function.rs +++ b/druid/examples/blocking_function.rs @@ -56,7 +56,7 @@ impl AppDelegate for Delegate { fn command( &mut self, _ctx: &mut DelegateCtx, - _target: &Target, + _target: Target, cmd: &Command, data: &mut AppState, _env: &Env, diff --git a/druid/examples/multiwin.rs b/druid/examples/multiwin.rs index 86bf749239..46094c4e8b 100644 --- a/druid/examples/multiwin.rs +++ b/druid/examples/multiwin.rs @@ -166,7 +166,7 @@ impl AppDelegate for Delegate { fn command( &mut self, ctx: &mut DelegateCtx, - target: &Target, + target: Target, cmd: &Command, data: &mut State, _env: &Env, @@ -184,7 +184,7 @@ impl AppDelegate for Delegate { data.selected = *cmd.get_object().unwrap(); let menu = make_menu::(data); let cmd = Command::new(druid::commands::SET_MENU, menu); - ctx.submit_command(cmd, *id); + ctx.submit_command(cmd, id); false } // wouldn't it be nice if a menu (like a button) could just mutate state @@ -193,14 +193,14 @@ impl AppDelegate for Delegate { data.menu_count += 1; let menu = make_menu::(data); let cmd = Command::new(druid::commands::SET_MENU, menu); - ctx.submit_command(cmd, *id); + ctx.submit_command(cmd, id); false } (Target::Window(id), &MENU_DECREMENT_ACTION) => { data.menu_count = data.menu_count.saturating_sub(1); let menu = make_menu::(data); let cmd = Command::new(druid::commands::SET_MENU, menu); - ctx.submit_command(cmd, *id); + ctx.submit_command(cmd, id); false } (_, &MENU_SWITCH_GLOW_ACTION) => { diff --git a/druid/src/app_delegate.rs b/druid/src/app_delegate.rs index 93cd52623f..2d53e5297b 100644 --- a/druid/src/app_delegate.rs +++ b/druid/src/app_delegate.rs @@ -91,7 +91,7 @@ pub trait AppDelegate { fn command( &mut self, ctx: &mut DelegateCtx, - target: &Target, + target: Target, cmd: &Command, data: &mut T, env: &Env, diff --git a/druid/src/win_handler.rs b/druid/src/win_handler.rs index 75f4946702..6513bdbb48 100644 --- a/druid/src/win_handler.rs +++ b/druid/src/win_handler.rs @@ -204,7 +204,7 @@ impl Inner { } } - fn delegate_cmd(&mut self, target: &Target, cmd: &Command) -> bool { + fn delegate_cmd(&mut self, target: Target, cmd: &Command) -> bool { self.with_delegate(|del, data, env, ctx| del.command(ctx, target, cmd, data, env)) .unwrap_or(true) } @@ -306,7 +306,7 @@ impl Inner { } fn dispatch_cmd(&mut self, target: Target, cmd: Command) { - if !self.delegate_cmd(&target, &cmd) { + if !self.delegate_cmd(target, &cmd) { return; }