From cbc244cdbe5e6b95c61083802281cfc2318d4f1d Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Tue, 27 Jan 2026 00:10:35 +0800 Subject: [PATCH] perf: enhance filename matching logic in IProfiles by using multiple regex patterns --- src-tauri/src/config/profiles.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/config/profiles.rs b/src-tauri/src/config/profiles.rs index 43887b027..8046cd6db 100644 --- a/src-tauri/src/config/profiles.rs +++ b/src-tauri/src/config/profiles.rs @@ -13,7 +13,7 @@ use smartstring::alias::String; use std::collections::{HashMap, HashSet}; use tokio::fs; -static PROFILE_FILE_RE: OnceCell = OnceCell::new(); +// static PROFILE_FILE_RE: OnceCell = OnceCell::new(); /// Define the `profiles.yaml` schema #[derive(Default, Debug, Clone, Deserialize, Serialize)] @@ -500,11 +500,19 @@ impl IProfiles { // r12345678.yaml (rules) // p12345678.yaml (proxies) // g12345678.yaml (groups) + + let patterns = [ + r"^[RL][a-zA-Z0-9]+\.yaml$", // Remote/Local profiles + r"^m[a-zA-Z0-9]+\.yaml$", // Merge files + r"^s[a-zA-Z0-9]+\.js$", // Script files + r"^[rpg][a-zA-Z0-9]+\.yaml$", // Rules/Proxies/Groups files + ]; - #[allow(clippy::unwrap_used)] - let re = PROFILE_FILE_RE - .get_or_init(|| Regex::new(r"^(?:[RLmprg][a-zA-Z0-9_-]+\.yaml|s[a-zA-Z0-9_-]+\.js)$").unwrap()); - re.is_match(filename) + patterns.iter().any(|pattern| { + regex::Regex::new(pattern) + .map(|re| re.is_match(filename)) + .unwrap_or(false) + }) } }