Skip to content

ext/intl: further fast ZPP usage. #14419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions ext/intl/dateformat/dateformat_format_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object)
{
zval *object,
*format = NULL;
const char *locale_str = NULL;
char *locale_str = NULL;
size_t locale_len;
bool pattern = false;
UDate date;
Expand All @@ -77,13 +77,15 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object)
DateFormat::EStyle dateStyle = DateFormat::kDefault,
timeStyle = DateFormat::kDefault;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "o|zs!",
&object, &format, &locale_str, &locale_len) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to remove the zend_parse_parameters in this function.

Z_PARAM_OBJECT(object)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL(format)
Z_PARAM_STRING_OR_NULL(locale_str, locale_len)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it possibly make more sense to use a zend_string here to be able to keep the const qualifier?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a possibility I may look after indeed.

ZEND_PARSE_PARAMETERS_END();

if (!locale_str) {
locale_str = intl_locale_get_default();
locale_str = (char *)intl_locale_get_default();
}

if (format == NULL || Z_TYPE_P(format) == IS_NULL) {
Expand Down
75 changes: 49 additions & 26 deletions ext/intl/grapheme/grapheme_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ PHP_FUNCTION(grapheme_strlen)
zend_long ret_len;
UErrorCode status;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &string, &string_len) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(string, string_len)
ZEND_PARSE_PARAMETERS_END();

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

Expand Down Expand Up @@ -89,9 +89,12 @@ PHP_FUNCTION(grapheme_strpos)
size_t noffset = 0;
zend_long ret_pos;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &haystack, &haystack_len, &needle, &needle_len, &loffset) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_STRING(haystack, haystack_len)
Z_PARAM_STRING(needle, needle_len)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(loffset)
ZEND_PARSE_PARAMETERS_END();

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

if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &haystack, &haystack_len, &needle, &needle_len, &loffset) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_STRING(haystack, haystack_len)
Z_PARAM_STRING(needle, needle_len)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(loffset)
ZEND_PARSE_PARAMETERS_END();

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

if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &haystack, &haystack_len, &needle, &needle_len, &loffset) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_STRING(haystack, haystack_len)
Z_PARAM_STRING(needle, needle_len)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(loffset)
ZEND_PARSE_PARAMETERS_END();

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

if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &haystack, &haystack_len, &needle, &needle_len, &loffset) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_STRING(haystack, haystack_len)
Z_PARAM_STRING(needle, needle_len)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(loffset)
ZEND_PARSE_PARAMETERS_END();

if ( OUTSIDE_STRING(loffset, haystack_len) ) {
zend_argument_value_error(3, "must be contained in argument #1 ($haystack)");
Expand Down Expand Up @@ -325,11 +337,14 @@ PHP_FUNCTION(grapheme_substr)
UBreakIterator* bi = NULL;
int sub_str_start_pos, sub_str_end_pos;
int32_t (*iter_func)(UBreakIterator *);
bool no_length = 1;
bool no_length = true;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l!", &str, &str_len, &lstart, &length, &no_length) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_STRING(str, str_len)
Z_PARAM_LONG(lstart)
Z_PARAM_OPTIONAL
Z_PARAM_LONG_OR_NULL(length, no_length)
ZEND_PARSE_PARAMETERS_END();

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

if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|b", &haystack, &haystack_len, &needle, &needle_len, &part) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_STRING(haystack, haystack_len)
Z_PARAM_STRING(needle, needle_len)
Z_PARAM_OPTIONAL
Z_PARAM_BOOL(part)
ZEND_PARSE_PARAMETERS_END();

if ( !f_ignore_case ) {

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

if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|llz", &str, &str_len, &size, &extract_type, &lstart, &next) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(2, 5)
Z_PARAM_STRING(str, str_len)
Z_PARAM_LONG(size)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(extract_type)
Z_PARAM_LONG(lstart)
Z_PARAM_ZVAL(next)
ZEND_PARSE_PARAMETERS_END();

if (lstart < 0) {
lstart += str_len;
Expand Down
Loading