mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-01 03:42:07 +08:00
refactor(enhance): fold lowercase helpers into single owned function
use_lowercase_owned disappears; the surviving use_lowercase takes the owned Mapping and borrowed callers clone at the call site.
This commit is contained in:
@@ -24,11 +24,7 @@ fn lowercase_key(key: &str) -> Value {
|
||||
Value::from(key.as_str())
|
||||
}
|
||||
|
||||
pub fn use_lowercase(config: &Mapping) -> Mapping {
|
||||
use_lowercase_owned(config.clone())
|
||||
}
|
||||
|
||||
pub fn use_lowercase_owned(config: Mapping) -> Mapping {
|
||||
pub fn use_lowercase(config: Mapping) -> Mapping {
|
||||
let mut lowercased = Mapping::new();
|
||||
|
||||
for (key, value) in config {
|
||||
|
||||
@@ -17,7 +17,7 @@ fn deep_merge(a: &mut Value, b: Value) {
|
||||
}
|
||||
|
||||
pub fn use_merge(merge: &Mapping, mut config: Mapping) -> Mapping {
|
||||
for (key, value) in use_lowercase(merge) {
|
||||
for (key, value) in use_lowercase(merge.clone()) {
|
||||
match (config.get_mut(&key), value) {
|
||||
(Some(Value::Mapping(existing)), Value::Mapping(overlay)) if key.as_str() == Some("dns") => {
|
||||
existing.extend(overlay);
|
||||
|
||||
@@ -8,7 +8,7 @@ mod tun;
|
||||
|
||||
use self::{
|
||||
chain::{AsyncChainItemFrom as _, ChainItem, ChainType},
|
||||
field::{use_keys, use_lowercase_owned, use_sort},
|
||||
field::{use_keys, use_lowercase, use_sort},
|
||||
merge::use_merge,
|
||||
script::use_script,
|
||||
seq::{SeqMap, use_seq},
|
||||
@@ -614,7 +614,7 @@ fn apply_builtin_scripts(mut config: Mapping, clash_core: Option<String>, enable
|
||||
.collect();
|
||||
if !items.is_empty() {
|
||||
// The JS path saw a lowercased view; lowercase once, only when a builtin runs.
|
||||
config = use_lowercase_owned(config);
|
||||
config = use_lowercase(config);
|
||||
for item in items {
|
||||
logging!(debug, Type::Core, "run builtin script {}", item.uid);
|
||||
config = match item.uid.as_str() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{process::AsyncHandler, utils::tmpl};
|
||||
|
||||
use super::field::{use_lowercase, use_lowercase_owned};
|
||||
use super::field::use_lowercase;
|
||||
use anyhow::{Error, Result};
|
||||
use boa_engine::{Context, JsString, JsValue, Source, js_string, native_function::NativeFunction, property::Attribute};
|
||||
use clash_verge_logging::{Type, logging};
|
||||
@@ -22,10 +22,10 @@ type EvalOutcome = (Result<Mapping, std::string::String>, Vec<(String, String)>)
|
||||
pub(super) async fn use_script(script: String, config: Mapping, name: String) -> ScriptResult {
|
||||
// The template is identity-plus-lowercasing; skip the Boa round-trip.
|
||||
if script == tmpl::ITEM_SCRIPT {
|
||||
return (use_lowercase_owned(config), vec![], vec![]);
|
||||
return (use_lowercase(config), vec![], vec![]);
|
||||
}
|
||||
|
||||
let json = match serde_json::to_string(&use_lowercase(&config)) {
|
||||
let json = match serde_json::to_string(&use_lowercase(config.clone())) {
|
||||
Ok(json) if json.len() <= MAX_JSON_SIZE => json,
|
||||
Ok(_) => {
|
||||
let message = "Configuration size exceeds maximum allowed size";
|
||||
@@ -173,7 +173,7 @@ fn eval_script(script: &str, config_json: &str, name: &String) -> EvalOutcome {
|
||||
}
|
||||
|
||||
match parse_json_safely(&result) {
|
||||
Ok(config) => (Ok(use_lowercase_owned(config)), outputs.lock().to_vec()),
|
||||
Ok(config) => (Ok(use_lowercase(config)), outputs.lock().to_vec()),
|
||||
Err(err) => {
|
||||
logging!(
|
||||
error,
|
||||
|
||||
Reference in New Issue
Block a user