mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 17:15:38 +08:00
Refactor string handling to use into() instead of to_string() for improved performance and consistency across the codebase. This change affects various modules including app.rs, clash.rs, config.rs, core.rs, service.rs, and others, ensuring that string conversions are streamlined and more idiomatic.
This commit is contained in:
@@ -35,7 +35,7 @@ impl IClashTemp {
|
||||
if let Some(Value::String(s)) = map.get_mut("secret")
|
||||
&& s.is_empty()
|
||||
{
|
||||
*s = "set-your-secret".to_string();
|
||||
*s = "set-your-secret".into();
|
||||
}
|
||||
Self(Self::guard(map))
|
||||
}
|
||||
@@ -323,10 +323,10 @@ impl IClashTemp {
|
||||
// 总是使用当前的 IPC 路径,确保配置文件与运行时路径一致
|
||||
ipc_path()
|
||||
.ok()
|
||||
.and_then(|path| path_to_str(&path).ok().map(|s| s.to_string()))
|
||||
.and_then(|path| path_to_str(&path).ok().map(|s| s.into()))
|
||||
.unwrap_or_else(|| {
|
||||
log::error!(target: "app", "Failed to get IPC path, using default");
|
||||
"127.0.0.1:9090".to_string()
|
||||
"127.0.0.1:9090".into()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,19 +58,19 @@ impl Config {
|
||||
if Self::profiles()
|
||||
.await
|
||||
.latest_ref()
|
||||
.get_item(&"Merge".to_string())
|
||||
.get_item(&"Merge".into())
|
||||
.is_err()
|
||||
{
|
||||
let merge_item = PrfItem::from_merge(Some("Merge".to_string()))?;
|
||||
let merge_item = PrfItem::from_merge(Some("Merge".into()))?;
|
||||
profiles_append_item_safe(merge_item.clone()).await?;
|
||||
}
|
||||
if Self::profiles()
|
||||
.await
|
||||
.latest_ref()
|
||||
.get_item(&"Script".to_string())
|
||||
.get_item(&"Script".into())
|
||||
.is_err()
|
||||
{
|
||||
let script_item = PrfItem::from_script(Some("Script".to_string()))?;
|
||||
let script_item = PrfItem::from_script(Some("Script".into()))?;
|
||||
profiles_append_item_safe(script_item.clone()).await?;
|
||||
}
|
||||
// 生成运行时配置
|
||||
@@ -238,8 +238,8 @@ mod tests {
|
||||
#[allow(unused_variables)]
|
||||
#[allow(clippy::expect_used)]
|
||||
fn test_prfitem_from_merge_size() {
|
||||
let merge_item = PrfItem::from_merge(Some("Merge".to_string()))
|
||||
.expect("Failed to create merge item in test");
|
||||
let merge_item =
|
||||
PrfItem::from_merge(Some("Merge".into())).expect("Failed to create merge item in test");
|
||||
let prfitem_size = mem::size_of_val(&merge_item);
|
||||
// Boxed version
|
||||
let boxed_merge_item = Box::new(merge_item);
|
||||
|
||||
@@ -312,12 +312,12 @@ impl PrfItem {
|
||||
Some(filename) => {
|
||||
let iter = percent_encoding::percent_decode(filename.as_bytes());
|
||||
let filename = iter.decode_utf8().unwrap_or_default();
|
||||
filename.split("''").last().map(|s| s.to_string())
|
||||
filename.split("''").last().map(|s| s.into())
|
||||
}
|
||||
None => match help::parse_str::<String>(filename, "filename") {
|
||||
Some(filename) => {
|
||||
let filename = filename.trim_matches('"');
|
||||
Some(filename.to_string())
|
||||
Some(filename.into())
|
||||
}
|
||||
None => None,
|
||||
},
|
||||
@@ -341,7 +341,7 @@ impl PrfItem {
|
||||
let home = match header.get("profile-web-page-url") {
|
||||
Some(value) => {
|
||||
let str_value = value.to_str().unwrap_or("");
|
||||
Some(str_value.to_string())
|
||||
Some(str_value.into())
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
|
||||
@@ -151,7 +151,7 @@ impl IProfiles {
|
||||
}
|
||||
|
||||
if self.current.is_none()
|
||||
&& (item.itype == Some("remote".to_string()) || item.itype == Some("local".to_string()))
|
||||
&& (item.itype == Some("remote".into()) || item.itype == Some("local".into()))
|
||||
{
|
||||
self.current = uid;
|
||||
}
|
||||
@@ -434,9 +434,7 @@ impl IProfiles {
|
||||
if current == uid {
|
||||
self.current = None;
|
||||
for item in items.iter() {
|
||||
if item.itype == Some("remote".to_string())
|
||||
|| item.itype == Some("local".to_string())
|
||||
{
|
||||
if item.itype == Some("remote".into()) || item.itype == Some("local".into()) {
|
||||
self.current = item.uid.clone();
|
||||
break;
|
||||
}
|
||||
@@ -602,7 +600,7 @@ impl IProfiles {
|
||||
if !active_files.contains(file_name) {
|
||||
match std::fs::remove_file(&path) {
|
||||
Ok(_) => {
|
||||
deleted_files.push(file_name.to_string());
|
||||
deleted_files.push(file_name.into());
|
||||
log::info!(target: "app", "已清理冗余文件: {file_name}");
|
||||
}
|
||||
Err(e) => {
|
||||
@@ -635,8 +633,8 @@ impl IProfiles {
|
||||
fn get_protected_global_files(&self) -> HashSet<String> {
|
||||
let mut protected_files = HashSet::new();
|
||||
|
||||
protected_files.insert("Merge.yaml".to_string());
|
||||
protected_files.insert("Script.js".to_string());
|
||||
protected_files.insert("Merge.yaml".into());
|
||||
protected_files.insert("Script.js".into());
|
||||
|
||||
protected_files
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ impl IVerge {
|
||||
"启动时发现无效的clash_core配置: '{}', 将自动修正为 'verge-mihomo'",
|
||||
core
|
||||
);
|
||||
config.clash_core = Some("verge-mihomo".to_string());
|
||||
config.clash_core = Some("verge-mihomo".into());
|
||||
needs_fix = true;
|
||||
}
|
||||
} else {
|
||||
@@ -267,7 +267,7 @@ impl IVerge {
|
||||
Type::Config,
|
||||
"启动时发现未配置clash_core, 将设置为默认值 'verge-mihomo'"
|
||||
);
|
||||
config.clash_core = Some("verge-mihomo".to_string());
|
||||
config.clash_core = Some("verge-mihomo".into());
|
||||
needs_fix = true;
|
||||
}
|
||||
|
||||
@@ -311,7 +311,7 @@ impl IVerge {
|
||||
pub fn get_valid_clash_core(&self) -> String {
|
||||
self.clash_core
|
||||
.clone()
|
||||
.unwrap_or_else(|| "verge-mihomo".to_string())
|
||||
.unwrap_or_else(|| "verge-mihomo".into())
|
||||
}
|
||||
|
||||
fn get_system_language() -> String {
|
||||
@@ -322,8 +322,8 @@ impl IVerge {
|
||||
let lang_code = sys_lang.split(['_', '-']).next().unwrap_or("en");
|
||||
let supported_languages = i18n::get_supported_languages();
|
||||
|
||||
if supported_languages.contains(&lang_code.to_string()) {
|
||||
lang_code.to_string()
|
||||
if supported_languages.contains(&lang_code.into()) {
|
||||
lang_code.into()
|
||||
} else {
|
||||
String::from("en")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user