mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-04-16 23:40:32 +08:00
perf: enhance filename matching logic in IProfiles by using multiple regex patterns
This commit is contained in:
parent
782e8d3352
commit
cbc244cdbe
@ -13,7 +13,7 @@ use smartstring::alias::String;
|
|||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|
||||||
static PROFILE_FILE_RE: OnceCell<Regex> = OnceCell::new();
|
// static PROFILE_FILE_RE: OnceCell<Regex> = OnceCell::new();
|
||||||
|
|
||||||
/// Define the `profiles.yaml` schema
|
/// Define the `profiles.yaml` schema
|
||||||
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
|
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
|
||||||
@ -500,11 +500,19 @@ impl IProfiles {
|
|||||||
// r12345678.yaml (rules)
|
// r12345678.yaml (rules)
|
||||||
// p12345678.yaml (proxies)
|
// p12345678.yaml (proxies)
|
||||||
// g12345678.yaml (groups)
|
// 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)]
|
patterns.iter().any(|pattern| {
|
||||||
let re = PROFILE_FILE_RE
|
regex::Regex::new(pattern)
|
||||||
.get_or_init(|| Regex::new(r"^(?:[RLmprg][a-zA-Z0-9_-]+\.yaml|s[a-zA-Z0-9_-]+\.js)$").unwrap());
|
.map(|re| re.is_match(filename))
|
||||||
re.is_match(filename)
|
.unwrap_or(false)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user