From 8bda22592e4a3b1c1735c6ca25d7f0404d511e53 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 14 Nov 2018 11:33:14 +0300 Subject: [PATCH] Eliminate useless $this related check --- ext/date/php_date.c | 24 ++++++++++++------- .../breakiterator/breakiterator_methods.cpp | 20 ++++++++-------- .../codepointiterator_methods.cpp | 2 +- .../rulebasedbreakiterator_methods.cpp | 8 +++---- ext/intl/calendar/calendar_methods.cpp | 20 +++++++++------- ext/intl/common/common_enum.h | 2 +- ext/intl/spoofchecker/spoofchecker_class.h | 2 +- 7 files changed, 45 insertions(+), 33 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 45438d4e43..be7c579d57 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -3269,7 +3269,8 @@ PHP_METHOD(DateTimeImmutable, modify) char *modify; size_t modify_len; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &object, date_ce_immutable, &modify, &modify_len) == FAILURE) { + object = &EX(This); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &modify, &modify_len) == FAILURE) { RETURN_FALSE; } @@ -3322,7 +3323,8 @@ PHP_METHOD(DateTimeImmutable, add) { zval *object, *interval, new_object; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "OO", &object, date_ce_immutable, &interval, date_ce_interval) == FAILURE) { + object = &EX(This); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &interval, date_ce_interval) == FAILURE) { RETURN_FALSE; } @@ -3378,7 +3380,8 @@ PHP_METHOD(DateTimeImmutable, sub) { zval *object, *interval, new_object; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "OO", &object, date_ce_immutable, &interval, date_ce_interval) == FAILURE) { + object = &EX(This); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &interval, date_ce_interval) == FAILURE) { RETURN_FALSE; } @@ -3482,7 +3485,8 @@ PHP_METHOD(DateTimeImmutable, setTimezone) zval *object, new_object; zval *timezone_object; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "OO", &object, date_ce_immutable, &timezone_object, date_ce_timezone) == FAILURE) { + object = &EX(This); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &timezone_object, date_ce_timezone) == FAILURE) { RETURN_FALSE; } @@ -3567,7 +3571,8 @@ PHP_METHOD(DateTimeImmutable, setTime) zval *object, new_object; zend_long h, i, s = 0, ms = 0; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Oll|ll", &object, date_ce_immutable, &h, &i, &s, &ms) == FAILURE) { + object = &EX(This); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|ll", &h, &i, &s, &ms) == FAILURE) { RETURN_FALSE; } @@ -3616,7 +3621,8 @@ PHP_METHOD(DateTimeImmutable, setDate) zval *object, new_object; zend_long y, m, d; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Olll", &object, date_ce_immutable, &y, &m, &d) == FAILURE) { + object = &EX(This); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll", &y, &m, &d) == FAILURE) { RETURN_FALSE; } @@ -3669,7 +3675,8 @@ PHP_METHOD(DateTimeImmutable, setISODate) zval *object, new_object; zend_long y, w, d = 1; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Oll|l", &object, date_ce_immutable, &y, &w, &d) == FAILURE) { + object = &EX(This); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|l", &y, &w, &d) == FAILURE) { RETURN_FALSE; } @@ -3717,7 +3724,8 @@ PHP_METHOD(DateTimeImmutable, setTimestamp) zval *object, new_object; zend_long timestamp; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", &object, date_ce_immutable, ×tamp) == FAILURE) { + object = &EX(This); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", ×tamp) == FAILURE) { RETURN_FALSE; } diff --git a/ext/intl/breakiterator/breakiterator_methods.cpp b/ext/intl/breakiterator/breakiterator_methods.cpp index 1d40a85494..00138afbc2 100644 --- a/ext/intl/breakiterator/breakiterator_methods.cpp +++ b/ext/intl/breakiterator/breakiterator_methods.cpp @@ -130,7 +130,7 @@ U_CFUNC PHP_FUNCTION(breakiter_create_code_point_instance) U_CFUNC PHP_FUNCTION(breakiter_get_text) { BREAKITER_METHOD_INIT_VARS; - object = getThis(); + object = &EX(This); if (zend_parse_parameters_none() == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -152,7 +152,7 @@ U_CFUNC PHP_FUNCTION(breakiter_set_text) UText *ut = NULL; zend_string *text; BREAKITER_METHOD_INIT_VARS; - object = getThis(); + object = &EX(This); if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &text) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -186,7 +186,7 @@ static void _breakiter_no_args_ret_int32( { char *msg; BREAKITER_METHOD_INIT_VARS; - object = getThis(); + object = &EX(This); if (zend_parse_parameters_none() == FAILURE) { spprintf(&msg, 0, "%s: bad arguments", func_name); @@ -210,7 +210,7 @@ static void _breakiter_int32_ret_int32( char *msg; zend_long arg; BREAKITER_METHOD_INIT_VARS; - object = getThis(); + object = &EX(This); if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &arg) == FAILURE) { spprintf(&msg, 0, "%s: bad arguments", func_name); @@ -287,7 +287,7 @@ U_CFUNC PHP_FUNCTION(breakiter_next) U_CFUNC PHP_FUNCTION(breakiter_current) { BREAKITER_METHOD_INIT_VARS; - object = getThis(); + object = &EX(This); if (zend_parse_parameters_none() == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -320,7 +320,7 @@ U_CFUNC PHP_FUNCTION(breakiter_is_boundary) { zend_long offset; BREAKITER_METHOD_INIT_VARS; - object = getThis(); + object = &EX(This); if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &offset) == FAILURE) { @@ -347,7 +347,7 @@ U_CFUNC PHP_FUNCTION(breakiter_get_locale) { zend_long locale_type; BREAKITER_METHOD_INIT_VARS; - object = getThis(); + object = &EX(This); if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &locale_type) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -375,7 +375,7 @@ U_CFUNC PHP_FUNCTION(breakiter_get_parts_iterator) { zend_long key_type = 0; BREAKITER_METHOD_INIT_VARS; - object = getThis(); + object = &EX(This); if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &key_type) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -400,7 +400,7 @@ U_CFUNC PHP_FUNCTION(breakiter_get_parts_iterator) U_CFUNC PHP_FUNCTION(breakiter_get_error_code) { BREAKITER_METHOD_INIT_VARS; - object = getThis(); + object = &EX(This); if (zend_parse_parameters_none() == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -420,7 +420,7 @@ U_CFUNC PHP_FUNCTION(breakiter_get_error_message) { zend_string* message = NULL; BREAKITER_METHOD_INIT_VARS; - object = getThis(); + object = &EX(This); if (zend_parse_parameters_none() == FAILURE) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, diff --git a/ext/intl/breakiterator/codepointiterator_methods.cpp b/ext/intl/breakiterator/codepointiterator_methods.cpp index f916915ae2..5feadc8528 100644 --- a/ext/intl/breakiterator/codepointiterator_methods.cpp +++ b/ext/intl/breakiterator/codepointiterator_methods.cpp @@ -30,7 +30,7 @@ static inline CodePointBreakIterator *fetch_cpbi(BreakIterator_object *bio) { U_CFUNC PHP_FUNCTION(cpbi_get_last_code_point) { BREAKITER_METHOD_INIT_VARS; - object = getThis(); + object = &EX(This); if (zend_parse_parameters_none() == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, diff --git a/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp b/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp index 97b9b19c11..6d64280676 100644 --- a/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp +++ b/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp @@ -102,7 +102,7 @@ U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, __construct) U_CFUNC PHP_FUNCTION(rbbi_get_rules) { BREAKITER_METHOD_INIT_VARS; - object = getThis(); + object = &EX(This); if (zend_parse_parameters_none() == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -129,7 +129,7 @@ U_CFUNC PHP_FUNCTION(rbbi_get_rules) U_CFUNC PHP_FUNCTION(rbbi_get_rule_status) { BREAKITER_METHOD_INIT_VARS; - object = getThis(); + object = &EX(This); if (zend_parse_parameters_none() == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -145,7 +145,7 @@ U_CFUNC PHP_FUNCTION(rbbi_get_rule_status) U_CFUNC PHP_FUNCTION(rbbi_get_rule_status_vec) { BREAKITER_METHOD_INIT_VARS; - object = getThis(); + object = &EX(This); if (zend_parse_parameters_none() == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -185,7 +185,7 @@ U_CFUNC PHP_FUNCTION(rbbi_get_rule_status_vec) U_CFUNC PHP_FUNCTION(rbbi_get_binary_rules) { BREAKITER_METHOD_INIT_VARS; - object = getThis(); + object = &EX(This); if (zend_parse_parameters_none() == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, diff --git a/ext/intl/calendar/calendar_methods.cpp b/ext/intl/calendar/calendar_methods.cpp index d85b06251b..dfe34a4f03 100644 --- a/ext/intl/calendar/calendar_methods.cpp +++ b/ext/intl/calendar/calendar_methods.cpp @@ -409,23 +409,25 @@ U_CFUNC PHP_FUNCTION(intlcal_set) int variant; /* number of args of the set() overload */ CALENDAR_METHOD_INIT_VARS; + object = getThis(); + /* must come before zpp because zpp would convert the args in the stack to 0 */ - if (ZEND_NUM_ARGS() > (getThis() ? 6 : 7) || + if (ZEND_NUM_ARGS() > (object ? 6 : 7) || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_set: too many arguments", 0); RETURN_FALSE; } - if (!getThis()) { + if (!object) { args++; } - variant = ZEND_NUM_ARGS() - (getThis() ? 0 : 1); + variant = ZEND_NUM_ARGS() - (object ? 0 : 1); while (variant > 2 && Z_TYPE(args[variant - 1]) == IS_NULL) { variant--; } if (variant == 4 || - zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), + zend_parse_method_parameters(ZEND_NUM_ARGS(), object, "Oll|llll", &object, Calendar_ce_ptr, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -472,17 +474,19 @@ U_CFUNC PHP_FUNCTION(intlcal_roll) zend_bool bool_variant_val = (zend_bool)-1; CALENDAR_METHOD_INIT_VARS; - if (ZEND_NUM_ARGS() > (getThis() ? 2 :3) || + object = getThis(); + + if (ZEND_NUM_ARGS() > (object ? 2 :3) || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_set: too many arguments", 0); RETURN_FALSE; } - if (!getThis()) { + if (!object) { args++; } if (!Z_ISUNDEF(args[1]) && (Z_TYPE(args[1]) == IS_TRUE || Z_TYPE(args[1]) == IS_FALSE)) { - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), + if (zend_parse_method_parameters(ZEND_NUM_ARGS(), object, "Olb", &object, Calendar_ce_ptr, &field, &bool_variant_val) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -490,7 +494,7 @@ U_CFUNC PHP_FUNCTION(intlcal_roll) RETURN_FALSE; } bool_variant_val = Z_TYPE(args[1]) == IS_TRUE? 1 : 0; - } else if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), + } else if (zend_parse_method_parameters(ZEND_NUM_ARGS(), object, "Oll", &object, Calendar_ce_ptr, &field, &value) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_roll: bad arguments", 0); diff --git a/ext/intl/common/common_enum.h b/ext/intl/common/common_enum.h index 9e47115304..227fed845d 100644 --- a/ext/intl/common/common_enum.h +++ b/ext/intl/common/common_enum.h @@ -40,7 +40,7 @@ extern "C" { #define INTLITERATOR_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(IntlIterator, ii) #define INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_ITERATOR, ii) #define INTLITERATOR_METHOD_FETCH_OBJECT\ - object = getThis(); \ + object = &EX(This); \ INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; \ if (ii->iterator == NULL) { \ intl_errors_set(&ii->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlIterator", 0); \ diff --git a/ext/intl/spoofchecker/spoofchecker_class.h b/ext/intl/spoofchecker/spoofchecker_class.h index c0cb0c5327..688bf4f964 100644 --- a/ext/intl/spoofchecker/spoofchecker_class.h +++ b/ext/intl/spoofchecker/spoofchecker_class.h @@ -57,7 +57,7 @@ extern zend_class_entry *Spoofchecker_ce_ptr; /* Auxiliary macros */ #define SPOOFCHECKER_METHOD_INIT_VARS \ - zval* object = getThis(); \ + zval* object = &EX(This); \ Spoofchecker_object* co = NULL; \ intl_error_reset(NULL); \ -- 2.50.0