From b7ffae965e39bfd6023994305b97a99c000cbf81 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 14 Jun 2026 13:30:49 +0900 Subject: refactor(pcre): take &mut matches in preg_*2 shim helpers The optional matches output was always passed Some(&mut ...) at every call site, so the Option wrapper added no value. Take &mut directly and inline the former internal helpers. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe-php-shim/src/preg.rs | 40 ++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'crates/shirabe-php-shim/src/preg.rs') diff --git a/crates/shirabe-php-shim/src/preg.rs b/crates/shirabe-php-shim/src/preg.rs index e9ee3bc..330ed4d 100644 --- a/crates/shirabe-php-shim/src/preg.rs +++ b/crates/shirabe-php-shim/src/preg.rs @@ -161,7 +161,7 @@ where pub fn preg_match2( pattern: &str, subject: &str, - matches: Option<&mut indexmap::IndexMap>>, + matches: &mut indexmap::IndexMap>, flags: i64, offset: usize, ) -> bool { @@ -169,12 +169,10 @@ pub fn preg_match2( let unmatched_as_null = flags & PREG_UNMATCHED_AS_NULL != 0; let caps = re.captures_at(subject, offset); - if let Some(out) = matches { - out.clear(); - if let Some(caps) = &caps { - let names: Vec> = re.capture_names().collect(); - *out = single_match_map(caps, &names, unmatched_as_null); - } + matches.clear(); + if let Some(caps) = &caps { + let names: Vec> = re.capture_names().collect(); + *matches = single_match_map(caps, &names, unmatched_as_null); } caps.is_some() @@ -183,7 +181,7 @@ pub fn preg_match2( pub fn preg_match_all2( pattern: &str, subject: &str, - matches: Option<&mut indexmap::IndexMap>>>, + matches: &mut indexmap::IndexMap>>, flags: i64, offset: usize, ) -> usize { @@ -207,14 +205,12 @@ pub fn preg_match_all2( } } - if let Some(out) = matches { - out.clear(); - for (g, column) in groups.into_iter().enumerate() { - if let Some(Some(name)) = names.get(g) { - out.insert(CaptureKey::ByName((*name).to_string()), column.clone()); - } - out.insert(CaptureKey::ByIndex(g), column); + matches.clear(); + for (g, column) in groups.into_iter().enumerate() { + if let Some(Some(name)) = names.get(g) { + matches.insert(CaptureKey::ByName((*name).to_string()), column.clone()); } + matches.insert(CaptureKey::ByIndex(g), column); } count @@ -223,7 +219,7 @@ pub fn preg_match_all2( pub fn preg_match_all_offset_capture2( pattern: &str, subject: &str, - matches: Option<&mut indexmap::IndexMap, i64)>>>, + matches: &mut indexmap::IndexMap, i64)>>, flags: i64, offset: usize, ) -> usize { @@ -246,14 +242,12 @@ pub fn preg_match_all_offset_capture2( } } - if let Some(out) = matches { - out.clear(); - for (g, column) in groups.into_iter().enumerate() { - if let Some(Some(name)) = names.get(g) { - out.insert(CaptureKey::ByName((*name).to_string()), column.clone()); - } - out.insert(CaptureKey::ByIndex(g), column); + matches.clear(); + for (g, column) in groups.into_iter().enumerate() { + if let Some(Some(name)) = names.get(g) { + matches.insert(CaptureKey::ByName((*name).to_string()), column.clone()); } + matches.insert(CaptureKey::ByIndex(g), column); } count -- cgit v1.3.1