perf: refactor IRuntime to use HashSet for exists_keys and improve related functions performance

This commit is contained in:
Tunglies
2025-11-22 16:25:50 +08:00
parent c82cefe80e
commit 82bed4910e
4 changed files with 68 additions and 58 deletions
+2 -2
View File
@@ -4,7 +4,7 @@ use anyhow::{Context as _, anyhow};
use clash_verge_logging::{Type, logging_error};
use serde_yaml_ng::Mapping;
use smartstring::alias::String;
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
/// 获取运行时配置
#[tauri::command]
@@ -31,7 +31,7 @@ pub async fn get_runtime_yaml() -> CmdResult<String> {
/// 获取运行时存在的键
#[tauri::command]
pub async fn get_runtime_exists() -> CmdResult<Vec<String>> {
pub async fn get_runtime_exists() -> CmdResult<HashSet<String>> {
Ok(Config::runtime().await.latest_arc().exists_keys.clone())
}
+2 -2
View File
@@ -9,7 +9,7 @@ use anyhow::{Result, anyhow};
use clash_verge_logging::{Type, logging};
use clash_verge_types::runtime::IRuntime;
use smartstring::alias::String;
use std::{path::PathBuf, time::Instant};
use std::{collections::HashSet, path::PathBuf, time::Instant};
use tauri_plugin_mihomo::Error as MihomoError;
impl CoreManager {
@@ -22,7 +22,7 @@ impl CoreManager {
Config::runtime().await.edit_draft(|d| {
*d = IRuntime {
config: Some(clash_config.to_owned()),
exists_keys: vec![],
exists_keys: HashSet::new(),
chain_logs: Default::default(),
}
});
+4 -5
View File
@@ -597,7 +597,7 @@ async fn apply_dns_settings(mut config: Mapping, enable_dns_settings: bool) -> M
/// Enhance mode
/// 返回最终订阅、该订阅包含的键、和script执行的结果
pub async fn enhance() -> (Mapping, Vec<String>, HashMap<String, ResultLog>) {
pub async fn enhance() -> (Mapping, HashSet<String>, HashMap<String, ResultLog>) {
// gather config values
let cfg_vals = get_config_values().await;
let ConfigValues {
@@ -667,11 +667,10 @@ pub async fn enhance() -> (Mapping, Vec<String>, HashMap<String, ResultLog>) {
// dns settings
config = apply_dns_settings(config, enable_dns_settings).await;
let mut exists_set = HashSet::new();
exists_set.extend(exists_keys);
let exists_keys: Vec<String> = exists_set.into_iter().collect();
let mut exists_keys_set = HashSet::new();
exists_keys_set.extend(exists_keys);
(config, exists_keys, result_map)
(config, exists_keys_set, result_map)
}
#[allow(clippy::expect_used)]