Skip to content

Commit bc6f333

Browse files
authored
ext/intl: further fast ZPP usage. (#14419)
1 parent 2f9de8b commit bc6f333

File tree

2 files changed

+57
-32
lines changed

2 files changed

+57
-32
lines changed

ext/intl/dateformat/dateformat_format_object.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object)
6666
{
6767
zval *object,
6868
*format = NULL;
69-
const char *locale_str = NULL;
69+
char *locale_str = NULL;
7070
size_t locale_len;
7171
bool pattern = false;
7272
UDate date;
@@ -77,13 +77,15 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object)
7777
DateFormat::EStyle dateStyle = DateFormat::kDefault,
7878
timeStyle = DateFormat::kDefault;
7979

80-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o|zs!",
81-
&object, &format, &locale_str, &locale_len) == FAILURE) {
82-
RETURN_THROWS();
83-
}
80+
ZEND_PARSE_PARAMETERS_START(1, 3)
81+
Z_PARAM_OBJECT(object)
82+
Z_PARAM_OPTIONAL
83+
Z_PARAM_ZVAL(format)
84+
Z_PARAM_STRING_OR_NULL(locale_str, locale_len)
85+
ZEND_PARSE_PARAMETERS_END();
8486

8587
if (!locale_str) {
86-
locale_str = intl_locale_get_default();
88+
locale_str = (char *)intl_locale_get_default();
8789
}
8890

8991
if (format == NULL || Z_TYPE_P(format) == IS_NULL) {

ext/intl/grapheme/grapheme_string.c

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ PHP_FUNCTION(grapheme_strlen)
3939
zend_long ret_len;
4040
UErrorCode status;
4141

42-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &string, &string_len) == FAILURE) {
43-
RETURN_THROWS();
44-
}
42+
ZEND_PARSE_PARAMETERS_START(1, 1)
43+
Z_PARAM_STRING(string, string_len)
44+
ZEND_PARSE_PARAMETERS_END();
4545

4646
ret_len = grapheme_ascii_check((unsigned char *)string, string_len);
4747

@@ -89,9 +89,12 @@ PHP_FUNCTION(grapheme_strpos)
8989
size_t noffset = 0;
9090
zend_long ret_pos;
9191

92-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &haystack, &haystack_len, &needle, &needle_len, &loffset) == FAILURE) {
93-
RETURN_THROWS();
94-
}
92+
ZEND_PARSE_PARAMETERS_START(2, 3)
93+
Z_PARAM_STRING(haystack, haystack_len)
94+
Z_PARAM_STRING(needle, needle_len)
95+
Z_PARAM_OPTIONAL
96+
Z_PARAM_LONG(loffset)
97+
ZEND_PARSE_PARAMETERS_END();
9598

9699
if ( OUTSIDE_STRING(loffset, haystack_len) ) {
97100
zend_argument_value_error(3, "must be contained in argument #1 ($haystack)");
@@ -139,9 +142,12 @@ PHP_FUNCTION(grapheme_stripos)
139142
zend_long ret_pos;
140143
int is_ascii;
141144

142-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &haystack, &haystack_len, &needle, &needle_len, &loffset) == FAILURE) {
143-
RETURN_THROWS();
144-
}
145+
ZEND_PARSE_PARAMETERS_START(2, 3)
146+
Z_PARAM_STRING(haystack, haystack_len)
147+
Z_PARAM_STRING(needle, needle_len)
148+
Z_PARAM_OPTIONAL
149+
Z_PARAM_LONG(loffset)
150+
ZEND_PARSE_PARAMETERS_END();
145151

146152
if ( OUTSIDE_STRING(loffset, haystack_len) ) {
147153
zend_argument_value_error(3, "must be contained in argument #1 ($haystack)");
@@ -200,9 +206,12 @@ PHP_FUNCTION(grapheme_strrpos)
200206
zend_long ret_pos;
201207
int is_ascii;
202208

203-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &haystack, &haystack_len, &needle, &needle_len, &loffset) == FAILURE) {
204-
RETURN_THROWS();
205-
}
209+
ZEND_PARSE_PARAMETERS_START(2, 3)
210+
Z_PARAM_STRING(haystack, haystack_len)
211+
Z_PARAM_STRING(needle, needle_len)
212+
Z_PARAM_OPTIONAL
213+
Z_PARAM_LONG(loffset)
214+
ZEND_PARSE_PARAMETERS_END();
206215

207216
if ( OUTSIDE_STRING(loffset, haystack_len) ) {
208217
zend_argument_value_error(3, "must be contained in argument #1 ($haystack)");
@@ -255,9 +264,12 @@ PHP_FUNCTION(grapheme_strripos)
255264
zend_long ret_pos;
256265
int is_ascii;
257266

258-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &haystack, &haystack_len, &needle, &needle_len, &loffset) == FAILURE) {
259-
RETURN_THROWS();
260-
}
267+
ZEND_PARSE_PARAMETERS_START(2, 3)
268+
Z_PARAM_STRING(haystack, haystack_len)
269+
Z_PARAM_STRING(needle, needle_len)
270+
Z_PARAM_OPTIONAL
271+
Z_PARAM_LONG(loffset)
272+
ZEND_PARSE_PARAMETERS_END();
261273

262274
if ( OUTSIDE_STRING(loffset, haystack_len) ) {
263275
zend_argument_value_error(3, "must be contained in argument #1 ($haystack)");
@@ -325,11 +337,14 @@ PHP_FUNCTION(grapheme_substr)
325337
UBreakIterator* bi = NULL;
326338
int sub_str_start_pos, sub_str_end_pos;
327339
int32_t (*iter_func)(UBreakIterator *);
328-
bool no_length = 1;
340+
bool no_length = true;
329341

330-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l!", &str, &str_len, &lstart, &length, &no_length) == FAILURE) {
331-
RETURN_THROWS();
332-
}
342+
ZEND_PARSE_PARAMETERS_START(2, 3)
343+
Z_PARAM_STRING(str, str_len)
344+
Z_PARAM_LONG(lstart)
345+
Z_PARAM_OPTIONAL
346+
Z_PARAM_LONG_OR_NULL(length, no_length)
347+
ZEND_PARSE_PARAMETERS_END();
333348

334349
if (lstart < INT32_MIN || lstart > INT32_MAX) {
335350
zend_argument_value_error(2, "is too large");
@@ -526,11 +541,14 @@ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_cas
526541
const char *found;
527542
size_t haystack_len, needle_len;
528543
int32_t ret_pos, uchar_pos;
529-
bool part = 0;
544+
bool part = false;
530545

531-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|b", &haystack, &haystack_len, &needle, &needle_len, &part) == FAILURE) {
532-
RETURN_THROWS();
533-
}
546+
ZEND_PARSE_PARAMETERS_START(2, 3)
547+
Z_PARAM_STRING(haystack, haystack_len)
548+
Z_PARAM_STRING(needle, needle_len)
549+
Z_PARAM_OPTIONAL
550+
Z_PARAM_BOOL(part)
551+
ZEND_PARSE_PARAMETERS_END();
534552

535553
if ( !f_ignore_case ) {
536554

@@ -702,9 +720,14 @@ PHP_FUNCTION(grapheme_extract)
702720
int ret_pos;
703721
zval *next = NULL; /* return offset of next part of the string */
704722

705-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|llz", &str, &str_len, &size, &extract_type, &lstart, &next) == FAILURE) {
706-
RETURN_THROWS();
707-
}
723+
ZEND_PARSE_PARAMETERS_START(2, 5)
724+
Z_PARAM_STRING(str, str_len)
725+
Z_PARAM_LONG(size)
726+
Z_PARAM_OPTIONAL
727+
Z_PARAM_LONG(extract_type)
728+
Z_PARAM_LONG(lstart)
729+
Z_PARAM_ZVAL(next)
730+
ZEND_PARSE_PARAMETERS_END();
708731

709732
if (lstart < 0) {
710733
lstart += str_len;

0 commit comments

Comments
 (0)