diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-14 13:30:49 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-14 13:30:49 +0900 |
| commit | b7ffae965e39bfd6023994305b97a99c000cbf81 (patch) | |
| tree | 62fbc076f0a0536fe3f86957ebb43cf2126f4abc /crates/shirabe-php-shim/src/preg.rs | |
| parent | 614616d4ceeb78dcf22df3e36a0fceb4c2d110c8 (diff) | |
| download | php-shirabe-b7ffae965e39bfd6023994305b97a99c000cbf81.tar.gz php-shirabe-b7ffae965e39bfd6023994305b97a99c000cbf81.tar.zst php-shirabe-b7ffae965e39bfd6023994305b97a99c000cbf81.zip | |
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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-shim/src/preg.rs')
| -rw-r--r-- | crates/shirabe-php-shim/src/preg.rs | 40 |
1 files changed, 17 insertions, 23 deletions
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<CaptureKey, Option<String>>>, + matches: &mut indexmap::IndexMap<CaptureKey, Option<String>>, 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<Option<&str>> = re.capture_names().collect(); - *out = single_match_map(caps, &names, unmatched_as_null); - } + matches.clear(); + if let Some(caps) = &caps { + let names: Vec<Option<&str>> = 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<CaptureKey, Vec<Option<String>>>>, + matches: &mut indexmap::IndexMap<CaptureKey, Vec<Option<String>>>, 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<CaptureKey, Vec<(Option<String>, i64)>>>, + matches: &mut indexmap::IndexMap<CaptureKey, Vec<(Option<String>, 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 |
