From 4b599f3b2bf28d2c81978dfd35977950a36de4af Mon Sep 17 00:00:00 2001 From: cfal Date: Mon, 26 Oct 2026 07:40:25 +0000 Subject: [PATCH] refactor(rule-set): reuse validated URLs during file decoding Retain the URL parsed at entry and derive its format hint at the existing selection point instead of parsing the declaration twice. Explicit formats still require valid delivery metadata, and format precedence is unchanged. --- src/rule_set/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rule_set/mod.rs b/src/rule_set/mod.rs index 97eafff0..dac4836c 100644 --- a/src/rule_set/mod.rs +++ b/src/rule_set/mod.rs @@ -621,7 +621,7 @@ fn read_file( path: PathBuf, compiler: &mut Compiler, ) -> io::Result> { - source.parsed_url()?; + let url = source.parsed_url()?; let start = std::time::Instant::now(); file.rewind()?; let metadata = file.metadata()?; @@ -637,7 +637,8 @@ fn read_file( file.read_exact(prefix)?; file.rewind()?; let remote_hint = compiler.remote_files.get(&path).copied().flatten(); - let format = source.format_with_hint(prefix, source.url_format()?.or(remote_hint))?; + let url_hint = url.and_then(|url| extension(Path::new(url.path()))); + let format = source.format_with_hint(prefix, url_hint.or(remote_hint))?; if !matches!( format, Format::MihomoYaml | Format::MihomoText | Format::Mrs