refactor: reduce clone operation (#5268)
* refactor: optimize item handling and improve profile management * refactor: update IVerge references to use references instead of owned values * refactor: update patch_verge to use data_ref for improved data handling * refactor: move handle_copy function to improve resource initialization logic * refactor: update profile handling to use references for improved memory efficiency * refactor: simplify get_item method and update profile item retrieval to use string slices * refactor: update profile validation and patching to use references for improved performance * refactor: update profile functions to use references for improved performance and memory efficiency * refactor: update profile patching functions to use references for improved memory efficiency * refactor: simplify merge function in PrfOption to enhance readability * refactor: update change_core function to accept a reference for improved memory efficiency * refactor: update PrfItem and profile functions to use references for improved memory efficiency * refactor: update resolve_scheme function to accept a reference for improved memory efficiency * refactor: update resolve_scheme function to accept a string slice for improved flexibility * refactor: simplify update_profile parameters and logic
This commit is contained in:
@@ -99,7 +99,7 @@ pub async fn import_profile(url: std::string::String, option: Option<PrfOption>)
|
||||
logging!(info, Type::Cmd, "[导入订阅] 开始导入: {}", url);
|
||||
|
||||
// 直接依赖 PrfItem::from_url 自身的超时/重试逻辑,不再使用 tokio::time::timeout 包裹
|
||||
let item = match PrfItem::from_url(&url, None, None, option).await {
|
||||
let item = &mut match PrfItem::from_url(&url, None, None, option.as_ref()).await {
|
||||
Ok(it) => {
|
||||
logging!(info, Type::Cmd, "[导入订阅] 下载完成,开始保存配置");
|
||||
it
|
||||
@@ -110,7 +110,7 @@ pub async fn import_profile(url: std::string::String, option: Option<PrfOption>)
|
||||
}
|
||||
};
|
||||
|
||||
match profiles_append_item_safe(item.clone()).await {
|
||||
match profiles_append_item_safe(item).await {
|
||||
Ok(_) => match profiles_save_file_safe().await {
|
||||
Ok(_) => {
|
||||
logging!(info, Type::Cmd, "[导入订阅] 配置文件保存成功");
|
||||
@@ -145,7 +145,7 @@ pub async fn import_profile(url: std::string::String, option: Option<PrfOption>)
|
||||
/// 调整profile的顺序
|
||||
#[tauri::command]
|
||||
pub async fn reorder_profile(active_id: String, over_id: String) -> CmdResult {
|
||||
match profiles_reorder_safe(active_id, over_id).await {
|
||||
match profiles_reorder_safe(&active_id, &over_id).await {
|
||||
Ok(_) => {
|
||||
log::info!(target: "app", "重新排序配置文件");
|
||||
Ok(())
|
||||
@@ -161,7 +161,7 @@ pub async fn reorder_profile(active_id: String, over_id: String) -> CmdResult {
|
||||
/// 创建一个新的配置文件
|
||||
#[tauri::command]
|
||||
pub async fn create_profile(item: PrfItem, file_data: Option<String>) -> CmdResult {
|
||||
match profiles_append_item_with_filedata_safe(item.clone(), file_data).await {
|
||||
match profiles_append_item_with_filedata_safe(&item, file_data).await {
|
||||
Ok(_) => {
|
||||
// 发送配置变更通知
|
||||
if let Some(uid) = &item.uid {
|
||||
@@ -180,7 +180,7 @@ pub async fn create_profile(item: PrfItem, file_data: Option<String>) -> CmdResu
|
||||
/// 更新配置文件
|
||||
#[tauri::command]
|
||||
pub async fn update_profile(index: String, option: Option<PrfOption>) -> CmdResult {
|
||||
match feat::update_profile(index, option, Some(true), Some(true)).await {
|
||||
match feat::update_profile(&index, option.as_ref(), true, true).await {
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => {
|
||||
log::error!(target: "app", "{}", e);
|
||||
@@ -194,9 +194,7 @@ pub async fn update_profile(index: String, option: Option<PrfOption>) -> CmdResu
|
||||
pub async fn delete_profile(index: String) -> CmdResult {
|
||||
println!("delete_profile: {}", index);
|
||||
// 使用Send-safe helper函数
|
||||
let should_update = profiles_delete_item_safe(index.clone())
|
||||
.await
|
||||
.stringify_err()?;
|
||||
let should_update = profiles_delete_item_safe(&index).await.stringify_err()?;
|
||||
profiles_save_file_safe().await.stringify_err()?;
|
||||
|
||||
if should_update {
|
||||
@@ -585,7 +583,7 @@ pub async fn patch_profile(index: String, profile: PrfItem) -> CmdResult {
|
||||
false
|
||||
};
|
||||
|
||||
profiles_patch_item_safe(index.clone(), profile)
|
||||
profiles_patch_item_safe(&index, &profile)
|
||||
.await
|
||||
.stringify_err()?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user