Skip to content

Commit 1b87772

Browse files
committed
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
1 parent 312f789 commit 1b87772

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

ext/standard/php_string.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,4 @@ PHPAPI bool php_binary_string_shuffle(php_random_algo_with_state engine, char *s
8080
#define PHP_PATHINFO_FILENAME 8
8181
#define PHP_PATHINFO_ALL (PHP_PATHINFO_DIRNAME | PHP_PATHINFO_BASENAME | PHP_PATHINFO_EXTENSION | PHP_PATHINFO_FILENAME)
8282

83-
#define PHP_STR_STRSPN 0
84-
#define PHP_STR_STRCSPN 1
85-
8683
#endif /* PHP_STRING_H */

ext/standard/string.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ PHP_FUNCTION(hex2bin)
207207
}
208208
/* }}} */
209209

210-
static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) /* {{{ */
210+
static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, bool is_strspn) /* {{{ */
211211
{
212212
zend_string *s11, *s22;
213213
zend_long start = 0, len = 0;
@@ -249,13 +249,12 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) /
249249
RETURN_LONG(0);
250250
}
251251

252-
if (behavior == PHP_STR_STRSPN) {
252+
if (is_strspn) {
253253
RETURN_LONG(php_strspn(ZSTR_VAL(s11) + start /*str1_start*/,
254254
ZSTR_VAL(s22) /*str2_start*/,
255255
ZSTR_VAL(s11) + start + len /*str1_end*/,
256256
ZSTR_VAL(s22) + ZSTR_LEN(s22) /*str2_end*/));
257257
} else {
258-
ZEND_ASSERT(behavior == PHP_STR_STRCSPN);
259258
RETURN_LONG(php_strcspn(ZSTR_VAL(s11) + start /*str1_start*/,
260259
ZSTR_VAL(s22) /*str2_start*/,
261260
ZSTR_VAL(s11) + start + len /*str1_end*/,
@@ -267,14 +266,14 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) /
267266
/* {{{ 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) */
268267
PHP_FUNCTION(strspn)
269268
{
270-
php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_STR_STRSPN);
269+
php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, /* is_strspn */ true);
271270
}
272271
/* }}} */
273272

274273
/* {{{ 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) */
275274
PHP_FUNCTION(strcspn)
276275
{
277-
php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_STR_STRCSPN);
276+
php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, /* is_strspn */ false);
278277
}
279278
/* }}} */
280279

0 commit comments

Comments
 (0)