From 17ee7f348cf9f2b690dcee468f050ab51895b5f8 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Thu, 8 Oct 2026 02:21:11 +0800 Subject: [PATCH] refactor(ipc): avoid redundant response copies --- src-tauri/src/cmd/network.rs | 19 ++++++++----------- src-tauri/src/cmd/profile.rs | 12 +++++------- src-tauri/src/cmd/runtime.rs | 7 +++---- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src-tauri/src/cmd/network.rs b/src-tauri/src/cmd/network.rs index 889413376..8d4aeed96 100644 --- a/src-tauri/src/cmd/network.rs +++ b/src-tauri/src/cmd/network.rs @@ -16,16 +16,16 @@ pub async fn get_sys_proxy() -> CmdResult { other => other.stringify_err()?, }; let Sysproxy { - ref host, - ref bypass, - ref port, - ref enable, + host, + bypass, + port, + enable, } = sys_proxy; Ok(SystemProxy { - enable: *enable, + enable, server: format!("{host}:{port}"), - bypass: bypass.to_string(), + bypass, }) } @@ -37,12 +37,9 @@ pub async fn get_auto_proxy() -> CmdResult { Err(error) if proxy_control::is_missing_network_service(&error) => Autoproxy::default(), other => other.stringify_err()?, }; - let Autoproxy { ref enable, ref url } = auto_proxy; + let Autoproxy { enable, url } = auto_proxy; - Ok(AutoProxy { - enable: *enable, - url: url.to_string(), - }) + Ok(AutoProxy { enable, url }) } #[tauri::command] diff --git a/src-tauri/src/cmd/profile.rs b/src-tauri/src/cmd/profile.rs index c70351059..d872f7cac 100644 --- a/src-tauri/src/cmd/profile.rs +++ b/src-tauri/src/cmd/profile.rs @@ -408,15 +408,16 @@ pub async fn patch_profiles_config(profiles: ProfileSelection) -> CmdResult #[tauri::command] #[specta::specta] pub async fn view_profile(index: std::string::String) -> CmdResult { - let index: String = index.into(); let profiles = Config::profiles().await; let profiles_ref = profiles.latest_arc(); let file = profiles_ref @@ -503,7 +503,6 @@ pub async fn view_profile(index: std::string::String) -> CmdResult { #[tauri::command] #[specta::specta] pub async fn read_profile_file(index: std::string::String) -> CmdResult { - let index: String = index.into(); let item = { let profiles = Config::profiles().await; let profiles_ref = profiles.latest_arc(); @@ -540,7 +539,6 @@ pub async fn read_profile_file(index: std::string::String) -> CmdResult CmdResult> { - let uid: String = uid.into(); let timer = Timer::global(); let next_time = timer.get_next_update_time(&uid).await; Ok(next_time) diff --git a/src-tauri/src/cmd/runtime.rs b/src-tauri/src/cmd/runtime.rs index 4664c2b49..c3a53a667 100644 --- a/src-tauri/src/cmd/runtime.rs +++ b/src-tauri/src/cmd/runtime.rs @@ -52,7 +52,6 @@ pub fn take_discarded_keys_notice() -> Option { pub async fn get_runtime_proxy_chain_config( proxy_chain_exit_node: std::string::String, ) -> CmdResult { - let proxy_chain_exit_node: String = proxy_chain_exit_node.into(); let runtime = Config::runtime().await; let runtime = runtime.latest_arc(); @@ -73,7 +72,7 @@ pub async fn get_runtime_proxy_chain_config( false } }) { - proxies_chain.push(proxy.to_owned()); + proxies_chain.push(proxy); proxy_name = proxy.get("dialer-proxy").map(|x| x.as_str()); } @@ -82,12 +81,12 @@ pub async fn get_runtime_proxy_chain_config( .find(|proxy| proxy.get("name").map(|x| x.as_str()) == proxy_name) && !proxies_chain.is_empty() { - proxies_chain.push(entry_proxy.to_owned()); + proxies_chain.push(entry_proxy); } proxies_chain.reverse(); - let mut config: HashMap> = HashMap::new(); + let mut config: HashMap> = HashMap::new(); config.insert("proxies".into(), proxies_chain);