From 879affc50810e1ebb20687265a9a4e9801e21af2 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 17 Aug 2026 03:43:21 +0900 Subject: refactor(preg): drop pass-through private helpers match_all5() was identical to match_all3(), and replace_impl() only forwarded its arguments to preg_replace2(). Call the destinations directly. --- crates/shirabe-pcre/src/preg.rs | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/crates/shirabe-pcre/src/preg.rs b/crates/shirabe-pcre/src/preg.rs index 8fb0c2e8..10ed1d5b 100644 --- a/crates/shirabe-pcre/src/preg.rs +++ b/crates/shirabe-pcre/src/preg.rs @@ -57,21 +57,13 @@ impl Preg { } pub fn match_all(pattern: impl PregPattern, subject: &str) -> usize { - Self::match_all5(pattern, subject, None) + Self::match_all3(pattern, subject, None) } pub fn match_all3( pattern: impl PregPattern, subject: &str, matches: Option<&mut IndexMap>>>, - ) -> usize { - Self::match_all5(pattern, subject, matches) - } - - fn match_all5( - pattern: impl PregPattern, - subject: &str, - matches: Option<&mut IndexMap>>>, ) -> usize { let mut internal: IndexMap>> = IndexMap::new(); let result = preg_match_all2(pattern, subject, &mut internal); @@ -100,7 +92,7 @@ impl Preg { } pub fn replace(pattern: impl PregPattern, replacement: &str, subject: &str) -> String { - Self::replace_impl(pattern, replacement, subject, -1, None) + preg_replace2(pattern, replacement, subject, -1, None) } pub fn replace4( @@ -109,7 +101,7 @@ impl Preg { subject: &str, limit: i64, ) -> String { - Self::replace_impl(pattern, replacement, subject, limit, None) + preg_replace2(pattern, replacement, subject, limit, None) } pub fn replace5( @@ -119,20 +111,7 @@ impl Preg { limit: i64, count: &mut usize, ) -> String { - Self::replace_impl(pattern, replacement, subject, limit, Some(count)) - } - - fn replace_impl( - pattern: impl PregPattern, - replacement: &str, - subject: &str, - limit: i64, - count: Option<&mut usize>, - ) -> String { - // `$subject` is statically a string here, so the is_scalar/is_array - // guards (ARRAY_MSG / INVALID_TYPE_MSG) of the PHP original are - // unreachable and not reproduced. - preg_replace2(pattern, replacement, subject, limit, count) + preg_replace2(pattern, replacement, subject, limit, Some(count)) } pub fn replace_callback) -> String>( @@ -246,7 +225,7 @@ impl Preg { subject: &str, matches: Option<&mut IndexMap>>>, ) -> bool { - Self::match_all5(pattern, subject, matches) > 0 + Self::match_all3(pattern, subject, matches) > 0 } pub fn is_match_all_with_offsets3( -- cgit v1.3.1-4-g156e