mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-17 17:32:15 +08:00
* fix: mechanical string conversions - &String parameters become &str (event payload fields borrow &str; wire format unchanged) - Cow/std-string double conversions collapse to a single Into - sha256 digests format through a shared hex lookup table instead of one format! allocation per byte - i18n placeholder replacement only allocates when the placeholder exists * perf(enhance): marshal scripts by value and diff fields by fingerprint - scripts cross into boa via JsValue::from_json/to_json instead of the JSON text round-trip (config clone + json string + UTF-16 JsString + stringify + re-parse all disappear); size guards use an allocation-free approximate walk - merge documents and tun/dns patches move values instead of deep-cloning whole sub-trees per pass - authoritative-field snapshots hash dns/hosts/tun values instead of cloning them around every chain item (9 snapshots per enhance) - proxy-name cleanup sets build from &str in one conversion * perf(config): write yaml headers in place and record selections without copying - save_yaml_str takes an optional header prefix written as separate chunks, so the MB-scale serialized payload is never duplicated by format! just to prepend a comment (profiles/verge/clash/runtime yaml all benefit; file bytes unchanged) - the runtime yaml string no longer round-trips through a prefixed copy; write_runtime_file adds the header when persisting - record/forget selected nodes mutate the stored selection list in place instead of cloning it per click * perf(tray): drop the redundant full rebuild in update_part update_part rebuilt the menu twice back to back: once without proxy groups, then a spawned full update_menu. Keep the partial rebuild only.
76 lines
1.9 KiB
Rust
76 lines
1.9 KiB
Rust
use serde_yaml_ng::{Mapping, Value};
|
|
use smartstring::alias::String;
|
|
|
|
pub const HANDLE_FIELDS: [&str; 12] = [
|
|
"mode",
|
|
"redir-port",
|
|
"tproxy-port",
|
|
"mixed-port",
|
|
"socks-port",
|
|
"port",
|
|
"allow-lan",
|
|
"log-level",
|
|
"ipv6",
|
|
"external-controller",
|
|
"secret",
|
|
"unified-delay",
|
|
];
|
|
|
|
pub const DEFAULT_FIELDS: [&str; 5] = ["proxies", "proxy-providers", "proxy-groups", "rule-providers", "rules"];
|
|
|
|
fn lowercase_key(key: &str) -> Value {
|
|
let mut key = String::from(key);
|
|
key.make_ascii_lowercase();
|
|
Value::from(key.as_str())
|
|
}
|
|
|
|
pub fn use_lowercase(config: Mapping) -> Mapping {
|
|
let mut lowercased = Mapping::new();
|
|
|
|
for (key, value) in config {
|
|
if let Some(key_str) = key.as_str() {
|
|
lowercased.insert(lowercase_key(key_str), value);
|
|
}
|
|
}
|
|
lowercased
|
|
}
|
|
|
|
pub fn use_sort(mut config: Mapping) -> Mapping {
|
|
let mut sorted = Mapping::new();
|
|
HANDLE_FIELDS.into_iter().for_each(|key| {
|
|
let key = Value::from(key);
|
|
if let Some(value) = config.remove(&key) {
|
|
sorted.insert(key, value);
|
|
}
|
|
});
|
|
|
|
let mut default_field_values = Mapping::new();
|
|
for (key, value) in config {
|
|
if let Some(key_str) = key.as_str() {
|
|
if DEFAULT_FIELDS.contains(&key_str) {
|
|
default_field_values.insert(key, value);
|
|
} else if !HANDLE_FIELDS.contains(&key_str) {
|
|
sorted.insert(key, value);
|
|
}
|
|
}
|
|
}
|
|
|
|
DEFAULT_FIELDS.into_iter().for_each(|key| {
|
|
let key = Value::from(key);
|
|
if let Some(value) = default_field_values.remove(&key) {
|
|
sorted.insert(key, value);
|
|
}
|
|
});
|
|
|
|
sorted
|
|
}
|
|
|
|
#[inline]
|
|
pub fn use_keys<'a>(config: &'a Mapping) -> impl Iterator<Item = String> + 'a {
|
|
config.iter().filter_map(|(key, _)| key.as_str()).map(|s: &str| {
|
|
let mut s: String = s.into();
|
|
s.make_ascii_lowercase();
|
|
s
|
|
})
|
|
}
|