Skip to content

Commit 354b647

Browse files
authored
ext/intl: calendar/locale use fast ZPP. (#14425)
1 parent 9437c32 commit 354b647

File tree

3 files changed

+103
-105
lines changed

3 files changed

+103
-105
lines changed

ext/intl/calendar/calendar_methods.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,17 @@ U_CFUNC PHP_METHOD(IntlCalendar, __construct)
7373
U_CFUNC PHP_FUNCTION(intlcal_create_instance)
7474
{
7575
zval *zv_timezone = NULL;
76-
const char *locale_str = NULL;
77-
size_t dummy;
76+
char *locale_str = NULL;
77+
size_t locale_len = 0;
7878
TimeZone *timeZone;
7979
UErrorCode status = U_ZERO_ERROR;
8080
intl_error_reset(NULL);
8181

82-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|zs!",
83-
&zv_timezone, &locale_str, &dummy) == FAILURE) {
84-
RETURN_THROWS();
85-
}
82+
ZEND_PARSE_PARAMETERS_START(0, 2)
83+
Z_PARAM_OPTIONAL
84+
Z_PARAM_ZVAL(zv_timezone)
85+
Z_PARAM_STRING_OR_NULL(locale_str, locale_len)
86+
ZEND_PARSE_PARAMETERS_END();
8687

8788
timeZone = timezone_process_timezone_argument(zv_timezone, NULL,
8889
"intlcal_create_instance");
@@ -91,7 +92,7 @@ U_CFUNC PHP_FUNCTION(intlcal_create_instance)
9192
}
9293

9394
if (!locale_str) {
94-
locale_str = intl_locale_get_default();
95+
locale_str = (char *)intl_locale_get_default();
9596
}
9697

9798
Calendar *cal = Calendar::createInstance(timeZone,
@@ -168,10 +169,11 @@ U_CFUNC PHP_FUNCTION(intlcal_get_keyword_values_for_locale)
168169
bool commonly_used;
169170
intl_error_reset(NULL);
170171

171-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ssb",
172-
&key, &key_len, &locale, &locale_len, &commonly_used) == FAILURE) {
173-
RETURN_THROWS();
174-
}
172+
ZEND_PARSE_PARAMETERS_START(3, 3)
173+
Z_PARAM_STRING(key, key_len)
174+
Z_PARAM_STRING(locale, locale_len)
175+
Z_PARAM_BOOL(commonly_used)
176+
ZEND_PARSE_PARAMETERS_END();
175177

176178
StringEnumeration *se = Calendar::getKeywordValuesForLocale(key,
177179
Locale::createFromName(locale), (UBool)commonly_used,
@@ -189,9 +191,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_now)
189191
{
190192
intl_error_reset(NULL);
191193

192-
if (zend_parse_parameters_none() == FAILURE) {
193-
RETURN_THROWS();
194-
}
194+
ZEND_PARSE_PARAMETERS_NONE();
195195

196196
RETURN_DOUBLE((double)Calendar::getNow());
197197
}
@@ -200,9 +200,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_available_locales)
200200
{
201201
intl_error_reset(NULL);
202202

203-
if (zend_parse_parameters_none() == FAILURE) {
204-
RETURN_THROWS();
205-
}
203+
ZEND_PARSE_PARAMETERS_NONE();
206204

207205
int32_t count;
208206
const Locale *availLocales = Calendar::getAvailableLocales(count);

ext/intl/calendar/gregoriancalendar_methods.cpp

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ static void _php_intlgregcal_constructor_body(
117117
// argument parsing
118118
if (variant <= 2) {
119119
if (zend_parse_parameters(MIN(ZEND_NUM_ARGS(), 2),
120-
"|z!s!", &tz_object, &locale, &locale_len) == FAILURE) {
121-
RETURN_THROWS();
122-
}
123-
}
124-
if (variant > 2 && zend_parse_parameters(ZEND_NUM_ARGS(),
125-
"lll|lll", &largs[0], &largs[1], &largs[2], &largs[3], &largs[4],
126-
&largs[5]) == FAILURE) {
127-
RETURN_THROWS();
120+
"|z!s!", &tz_object, &locale, &locale_len) == FAILURE) {
121+
RETURN_THROWS();
122+
}
123+
}
124+
if (variant > 2 && zend_parse_parameters(ZEND_NUM_ARGS(),
125+
"lll|lll", &largs[0], &largs[1], &largs[2], &largs[3], &largs[4],
126+
&largs[5]) == FAILURE) {
127+
RETURN_THROWS();
128128
}
129129

130130
if (error_handling != NULL) {
@@ -238,9 +238,11 @@ U_CFUNC PHP_METHOD(IntlGregorianCalendar, createFromDate)
238238

239239
intl_error_reset(NULL);
240240

241-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll", &year, &month, &day) == FAILURE) {
242-
RETURN_THROWS();
243-
}
241+
ZEND_PARSE_PARAMETERS_START(3, 3)
242+
Z_PARAM_LONG(year)
243+
Z_PARAM_LONG(month)
244+
Z_PARAM_LONG(day)
245+
ZEND_PARSE_PARAMETERS_END();
244246

245247
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(year, 1);
246248
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(month, 2);
@@ -273,9 +275,15 @@ U_CFUNC PHP_METHOD(IntlGregorianCalendar, createFromDateTime)
273275

274276
intl_error_reset(NULL);
275277

276-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lllll|l!", &year, &month, &day, &hour, &minute, &second, &second_is_null) == FAILURE) {
277-
RETURN_THROWS();
278-
}
278+
ZEND_PARSE_PARAMETERS_START(5, 6)
279+
Z_PARAM_LONG(year)
280+
Z_PARAM_LONG(month)
281+
Z_PARAM_LONG(day)
282+
Z_PARAM_LONG(hour)
283+
Z_PARAM_LONG(minute)
284+
Z_PARAM_OPTIONAL
285+
Z_PARAM_LONG_OR_NULL(second, second_is_null)
286+
ZEND_PARSE_PARAMETERS_END();
279287

280288
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(year, 1);
281289
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(month, 2);
@@ -310,9 +318,10 @@ U_CFUNC PHP_FUNCTION(intlgregcal_set_gregorian_change)
310318
CALENDAR_METHOD_INIT_VARS;
311319

312320
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
313-
"Od", &object, GregorianCalendar_ce_ptr, &date) == FAILURE) {
314-
RETURN_THROWS();
315-
}
321+
"Od", &object, GregorianCalendar_ce_ptr, &date) == FAILURE) {
322+
RETURN_THROWS();
323+
}
324+
316325

317326
CALENDAR_METHOD_FETCH_OBJECT;
318327

@@ -328,9 +337,10 @@ U_CFUNC PHP_FUNCTION(intlgregcal_get_gregorian_change)
328337
CALENDAR_METHOD_INIT_VARS;
329338

330339
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
331-
"O", &object, GregorianCalendar_ce_ptr) == FAILURE) {
340+
"O", &object, GregorianCalendar_ce_ptr) == FAILURE) {
332341
RETURN_THROWS();
333-
}
342+
}
343+
334344

335345
CALENDAR_METHOD_FETCH_OBJECT;
336346

@@ -343,9 +353,10 @@ U_CFUNC PHP_FUNCTION(intlgregcal_is_leap_year)
343353
CALENDAR_METHOD_INIT_VARS;
344354

345355
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
346-
"Ol", &object, GregorianCalendar_ce_ptr, &year) == FAILURE) {
347-
RETURN_THROWS();
348-
}
356+
"Ol", &object, GregorianCalendar_ce_ptr, &year) == FAILURE) {
357+
RETURN_THROWS();
358+
}
359+
349360

350361
if (UNEXPECTED(year < INT32_MIN || year > INT32_MAX)) {
351362
zend_argument_value_error(hasThis() ? 1 : 2, "must be between %d and %d", INT32_MIN, INT32_MAX);

0 commit comments

Comments
 (0)