From 791ef1cd465597ff43dab4216c4b00e9e4160da8 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 6 Aug 2026 06:25:10 +0900 Subject: refactor(php-shim): split in_array into strict and loose variants --- crates/shirabe-php-shim/src/array.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'crates/shirabe-php-shim/src/array.rs') diff --git a/crates/shirabe-php-shim/src/array.rs b/crates/shirabe-php-shim/src/array.rs index 29338aae..86a78dd2 100644 --- a/crates/shirabe-php-shim/src/array.rs +++ b/crates/shirabe-php-shim/src/array.rs @@ -585,18 +585,20 @@ fn php_slice_bounds(len: i64, offset: i64, length: Option) -> (usize, usize (start as usize, end as usize) } -pub fn in_array(needle: PhpMixed, haystack: &PhpMixed, strict: bool) -> bool { - let values: Vec<&PhpMixed> = match haystack { - PhpMixed::List(items) => items.iter().collect(), - PhpMixed::Array(map) => map.values().collect(), - _ => return false, - }; - - if strict { - values.iter().any(|value| **value == needle) - } else { - values.iter().any(|value| loose_eq(value, &needle)) - } +pub fn in_array_strict<'a>( + needle: impl Into, + haystack: impl IntoIterator, +) -> bool { + let needle = needle.into(); + haystack.into_iter().any(|value| *value == needle) +} + +pub fn in_array_loose<'a>( + needle: impl Into, + haystack: impl IntoIterator, +) -> bool { + let needle = needle.into(); + haystack.into_iter().any(|value| loose_eq(value, &needle)) } /// PHP numeric-string-aware conversion to a number, used by loose comparison. -- cgit v1.3.1