From 1b87772f40d2e94a97e8657f576f33fa9aceb1b8 Mon Sep 17 00:00:00 2001 From: Gina Peter Bnayard Date: Tue, 13 Aug 2024 18:12:43 +0200 Subject: [PATCH] ext/standard/string.c: Refactor php_spn_common_handler() Main objective is to remove the PHP_STR_STR(C)SPN symbols which are only used with this static function --- ext/standard/php_string.h | 3 --- ext/standard/string.c | 9 ++++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h index 1be7d9b283772..f00ff830682ce 100644 --- a/ext/standard/php_string.h +++ b/ext/standard/php_string.h @@ -80,7 +80,4 @@ PHPAPI bool php_binary_string_shuffle(php_random_algo_with_state engine, char *s #define PHP_PATHINFO_FILENAME 8 #define PHP_PATHINFO_ALL (PHP_PATHINFO_DIRNAME | PHP_PATHINFO_BASENAME | PHP_PATHINFO_EXTENSION | PHP_PATHINFO_FILENAME) -#define PHP_STR_STRSPN 0 -#define PHP_STR_STRCSPN 1 - #endif /* PHP_STRING_H */ diff --git a/ext/standard/string.c b/ext/standard/string.c index 1082066dcec55..70b5ffd0bd0e9 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -207,7 +207,7 @@ PHP_FUNCTION(hex2bin) } /* }}} */ -static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) /* {{{ */ +static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, bool is_strspn) /* {{{ */ { zend_string *s11, *s22; zend_long start = 0, len = 0; @@ -249,13 +249,12 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) / RETURN_LONG(0); } - if (behavior == PHP_STR_STRSPN) { + if (is_strspn) { RETURN_LONG(php_strspn(ZSTR_VAL(s11) + start /*str1_start*/, ZSTR_VAL(s22) /*str2_start*/, ZSTR_VAL(s11) + start + len /*str1_end*/, ZSTR_VAL(s22) + ZSTR_LEN(s22) /*str2_end*/)); } else { - ZEND_ASSERT(behavior == PHP_STR_STRCSPN); RETURN_LONG(php_strcspn(ZSTR_VAL(s11) + start /*str1_start*/, ZSTR_VAL(s22) /*str2_start*/, ZSTR_VAL(s11) + start + len /*str1_end*/, @@ -267,14 +266,14 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) / /* {{{ Finds length of initial segment consisting entirely of characters found in mask. If start or/and length is provided works like strspn(substr($s,$start,$len),$good_chars) */ PHP_FUNCTION(strspn) { - php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_STR_STRSPN); + php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, /* is_strspn */ true); } /* }}} */ /* {{{ Finds length of initial segment consisting entirely of characters not found in mask. If start or/and length is provide works like strcspn(substr($s,$start,$len),$bad_chars) */ PHP_FUNCTION(strcspn) { - php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_STR_STRCSPN); + php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, /* is_strspn */ false); } /* }}} */