perf: utilize smartstring for string handling (#5149)

* perf: utilize smartstring for string handling

- Updated various modules to replace standard String with smartstring::alias::String for improved performance and memory efficiency.
- Adjusted string manipulations and conversions throughout the codebase to ensure compatibility with the new smartstring type.
- Enhanced readability and maintainability by using `.into()` for conversions where applicable.
- Ensured that all instances of string handling in configuration, logging, and network management leverage the benefits of smartstring.

* fix: replace wrap_err with stringify_err for better error handling in UWP tool invocation

* refactor: update import path for StringifyErr and adjust string handling in sysopt

* fix: correct import path for CmdResult in UWP module

* fix: update argument type for execute_sysproxy_command to use std::string::String

* fix: add missing CmdResult import in UWP platform module

* fix: improve string handling and error messaging across multiple files

* style: format code for improved readability and consistency across multiple files

* fix: remove unused file
This commit is contained in:
Tunglies
2025-10-22 16:25:44 +08:00
committed by GitHub
parent fe96a7030a
commit a05ea64bcd
50 changed files with 361 additions and 272 deletions

View File

@@ -1,4 +1,5 @@
use anyhow::Result;
use smartstring::alias::String;
use std::path::Path;
use std::sync::Arc;
use tauri_plugin_shell::ShellExt;
@@ -124,7 +125,7 @@ impl CoreConfigValidator {
let content = match std::fs::read_to_string(config_path) {
Ok(content) => content,
Err(err) => {
let error_msg = format!("Failed to read file: {err}");
let error_msg = format!("Failed to read file: {err}").into();
logging!(error, Type::Validate, "无法读取文件: {}", error_msg);
return Ok((false, error_msg));
}
@@ -138,7 +139,7 @@ impl CoreConfigValidator {
}
Err(err) => {
// 使用标准化的前缀,以便错误处理函数能正确识别
let error_msg = format!("YAML syntax error: {err}");
let error_msg = format!("YAML syntax error: {err}").into();
logging!(error, Type::Validate, "YAML语法错误: {}", error_msg);
Ok((false, error_msg))
}
@@ -151,7 +152,7 @@ impl CoreConfigValidator {
let content = match std::fs::read_to_string(path) {
Ok(content) => content,
Err(err) => {
let error_msg = format!("Failed to read script file: {err}");
let error_msg = format!("Failed to read script file: {err}").into();
logging!(warn, Type::Validate, "脚本语法错误: {}", err);
//handle::Handle::notice_message("config_validate::script_syntax_error", &error_msg);
return Ok((false, error_msg));
@@ -184,7 +185,7 @@ impl CoreConfigValidator {
Ok((true, String::new()))
}
Err(err) => {
let error_msg = format!("Script syntax error: {err}");
let error_msg = format!("Script syntax error: {err}").into();
logging!(warn, Type::Validate, "脚本语法错误: {}", err);
//handle::Handle::notice_message("config_validate::script_syntax_error", &error_msg);
Ok((false, error_msg))
@@ -205,7 +206,7 @@ impl CoreConfigValidator {
// 检查文件是否存在
if !std::path::Path::new(config_path).exists() {
let error_msg = format!("File not found: {config_path}");
let error_msg = format!("File not found: {config_path}").into();
//handle::Handle::notice_message("config_validate::file_not_found", &error_msg);
return Ok((false, error_msg));
}
@@ -282,13 +283,13 @@ impl CoreConfigValidator {
// 使用子进程运行clash验证配置
let output = app_handle
.shell()
.sidecar(clash_core)?
.sidecar(clash_core.as_str())?
.args(["-t", "-d", app_dir_str, "-f", config_path])
.output()
.await?;
let stderr = String::from_utf8_lossy(&output.stderr);
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = std::string::String::from_utf8_lossy(&output.stderr);
let stdout = std::string::String::from_utf8_lossy(&output.stdout);
// 检查进程退出状态和错误输出
let error_keywords = ["FATA", "fatal", "Parse config error", "level=fatal"];
@@ -314,7 +315,7 @@ impl CoreConfigValidator {
};
logging!(info, Type::Validate, "-------- 验证结束 --------");
Ok((false, error_msg)) // 返回错误消息给调用者处理
Ok((false, error_msg.into())) // 返回错误消息给调用者处理
} else {
logging!(info, Type::Validate, "验证成功");
logging!(info, Type::Validate, "-------- 验证结束 --------");