mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-04-18 00:11:08 +08:00
perf: consolidate regex patterns for filename matching in IProfiles
This commit is contained in:
parent
ef5050564b
commit
a07069e7ea
@ -5,13 +5,15 @@ use crate::utils::{
|
|||||||
};
|
};
|
||||||
use anyhow::{Context as _, Result, bail};
|
use anyhow::{Context as _, Result, bail};
|
||||||
use clash_verge_logging::{Type, logging};
|
use clash_verge_logging::{Type, logging};
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
|
use regex::Regex;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_yaml_ng::Mapping;
|
use serde_yaml_ng::Mapping;
|
||||||
use smartstring::alias::String;
|
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)]
|
||||||
@ -499,18 +501,14 @@ impl IProfiles {
|
|||||||
// p12345678.yaml (proxies)
|
// p12345678.yaml (proxies)
|
||||||
// g12345678.yaml (groups)
|
// g12345678.yaml (groups)
|
||||||
|
|
||||||
let patterns = [
|
PROFILE_FILE_RE
|
||||||
r"^[RL][a-zA-Z0-9]+\.yaml$", // Remote/Local profiles
|
.get_or_init(|| {
|
||||||
r"^m[a-zA-Z0-9]+\.yaml$", // Merge files
|
regex::Regex::new(
|
||||||
r"^s[a-zA-Z0-9]+\.js$", // Script files
|
r"^(?:[RL][a-zA-Z0-9]+\.yaml|m[a-zA-Z0-9]+\.yaml|s[a-zA-Z0-9]+\.js|[rpg][a-zA-Z0-9]+\.yaml)$",
|
||||||
r"^[rpg][a-zA-Z0-9]+\.yaml$", // Rules/Proxies/Groups files
|
)
|
||||||
];
|
.unwrap()
|
||||||
|
})
|
||||||
patterns.iter().any(|pattern| {
|
.is_match(filename)
|
||||||
regex::Regex::new(pattern)
|
|
||||||
.map(|re| re.is_match(filename))
|
|
||||||
.unwrap_or(false)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user