]> granicus.if.org Git - php/commitdiff
Move exceprional code into helper & zend_fetch_var_address_helper() micro-optimization.
authorDmitry Stogov <dmitry@zend.com>
Wed, 21 Feb 2018 14:09:42 +0000 (17:09 +0300)
committerDmitry Stogov <dmitry@zend.com>
Wed, 21 Feb 2018 14:09:42 +0000 (17:09 +0300)
Zend/zend_execute.c
Zend/zend_vm_def.h
Zend/zend_vm_execute.h

index be5de9cbc7b19965672293d2aec6ebbd8971f712..93f6334ecc259683cfe9b700cff76c3899a812b5 100644 (file)
@@ -2261,6 +2261,42 @@ use_read_property:
        }
 }
 
+static zend_never_inline void zend_fetch_this_var(int type OPLINE_DC EXECUTE_DATA_DC)
+{
+       zval *result = EX_VAR(opline->result.var);
+
+       switch (type) {
+               case BP_VAR_R:
+                       if (EXPECTED(Z_TYPE(EX(This)) == IS_OBJECT)) {
+                               ZVAL_OBJ(result, Z_OBJ(EX(This)));
+                               Z_ADDREF_P(result);
+                       } else {
+                               ZVAL_NULL(result);
+                               zend_error(E_NOTICE,"Undefined variable: this");
+                       }
+                       break;
+               case BP_VAR_IS:
+                       if (EXPECTED(Z_TYPE(EX(This)) == IS_OBJECT)) {
+                               ZVAL_OBJ(result, Z_OBJ(EX(This)));
+                               Z_ADDREF_P(result);
+                       } else {
+                               ZVAL_NULL(result);
+                       }
+                       break;
+               case BP_VAR_RW:
+               case BP_VAR_W:
+                       ZVAL_UNDEF(result);
+                       zend_throw_error(NULL, "Cannot re-assign $this");
+                       break;
+               case BP_VAR_UNSET:
+                       ZVAL_UNDEF(result);
+                       zend_throw_error(NULL, "Cannot unset $this");
+                       break;
+               EMPTY_SWITCH_DEFAULT_CASE()
+       }
+}
+
+
 #if ZEND_INTENSIVE_DEBUGGING
 
 #define CHECK_SYMBOL_TABLES()                                                                                                  \
index 95da21daadafffbc3bb4cc6187c5443839b01266..730d1d60dfb1e951eb09bc0322348434d3b81834 100644 (file)
@@ -1403,60 +1403,24 @@ ZEND_VM_HELPER(zend_fetch_var_address_helper, CONST|TMPVAR|CV, UNUSED, int type)
        retval = zend_hash_find_ex(target_symbol_table, name, OP1_TYPE == IS_CONST);
        if (retval == NULL) {
                if (UNEXPECTED(zend_string_equals(name, ZSTR_KNOWN(ZEND_STR_THIS)))) {
-                       zval *result;
-
 ZEND_VM_C_LABEL(fetch_this):
-                       result = EX_VAR(opline->result.var);
-                       switch (type) {
-                               case BP_VAR_R:
-                                       if (EXPECTED(Z_TYPE(EX(This)) == IS_OBJECT)) {
-                                               ZVAL_OBJ(result, Z_OBJ(EX(This)));
-                                               Z_ADDREF_P(result);
-                                       } else {
-                                               ZVAL_NULL(result);
-                                               zend_error(E_NOTICE,"Undefined variable: this");
-                                       }
-                                       break;
-                               case BP_VAR_IS:
-                                       if (EXPECTED(Z_TYPE(EX(This)) == IS_OBJECT)) {
-                                               ZVAL_OBJ(result, Z_OBJ(EX(This)));
-                                               Z_ADDREF_P(result);
-                                       } else {
-                                               ZVAL_NULL(result);
-                                       }
-                                       break;
-                               case BP_VAR_RW:
-                               case BP_VAR_W:
-                                       ZVAL_UNDEF(result);
-                                       zend_throw_error(NULL, "Cannot re-assign $this");
-                                       break;
-                               case BP_VAR_UNSET:
-                                       ZVAL_UNDEF(result);
-                                       zend_throw_error(NULL, "Cannot unset $this");
-                                       break;
-                               EMPTY_SWITCH_DEFAULT_CASE()
-                       }
+                       zend_fetch_this_var(type OPLINE_CC EXECUTE_DATA_CC);
                        if (OP1_TYPE != IS_CONST) {
                                zend_tmp_string_release(tmp_name);
                        }
                        ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
                }
-               switch (type) {
-                       case BP_VAR_R:
-                       case BP_VAR_UNSET:
-                               zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
-                               /* break missing intentionally */
-                       case BP_VAR_IS:
-                               retval = &EG(uninitialized_zval);
-                               break;
-                       case BP_VAR_RW:
-                               zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
+               if (type == BP_VAR_W) {
+                       retval = zend_hash_add_new(target_symbol_table, name, &EG(uninitialized_zval));
+               } else if (type == BP_VAR_IS) {
+                       retval = &EG(uninitialized_zval);
+               } else {
+                       zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
+                       if (type == BP_VAR_RW) {
                                retval = zend_hash_update(target_symbol_table, name, &EG(uninitialized_zval));
-                               break;
-                       case BP_VAR_W:
-                               retval = zend_hash_add_new(target_symbol_table, name, &EG(uninitialized_zval));
-                               break;
-                       EMPTY_SWITCH_DEFAULT_CASE()
+                       } else {
+                               retval = &EG(uninitialized_zval);
+                       }
                }
        /* GLOBAL or $$name variable may be an INDIRECT pointer to CV */
        } else if (Z_TYPE_P(retval) == IS_INDIRECT) {
@@ -1465,21 +1429,17 @@ ZEND_VM_C_LABEL(fetch_this):
                        if (UNEXPECTED(zend_string_equals(name, ZSTR_KNOWN(ZEND_STR_THIS)))) {
                                ZEND_VM_C_GOTO(fetch_this);
                        }
-                       switch (type) {
-                               case BP_VAR_R:
-                               case BP_VAR_UNSET:
-                                       zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
-                                       /* break missing intentionally */
-                               case BP_VAR_IS:
-                                       retval = &EG(uninitialized_zval);
-                                       break;
-                               case BP_VAR_RW:
-                                       zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
-                                       /* break missing intentionally */
-                               case BP_VAR_W:
+                       if (type == BP_VAR_W) {
+                               ZVAL_NULL(retval);
+                       } else if (type == BP_VAR_IS) {
+                               retval = &EG(uninitialized_zval);
+                       } else {
+                               zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
+                               if (type == BP_VAR_RW) {
                                        ZVAL_NULL(retval);
-                                       break;
-                               EMPTY_SWITCH_DEFAULT_CASE()
+                               } else {
+                                       retval = &EG(uninitialized_zval);
+                               }
                        }
                }
        }
index 093cf8714235363353c62cce09626c1887191d4b..79e69c71bb7aadbae6e966b521fd023995957947 100644 (file)
@@ -8401,60 +8401,24 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_fetch_var_address_helper_SPEC_
        retval = zend_hash_find_ex(target_symbol_table, name, IS_CONST == IS_CONST);
        if (retval == NULL) {
                if (UNEXPECTED(zend_string_equals(name, ZSTR_KNOWN(ZEND_STR_THIS)))) {
-                       zval *result;
-
 fetch_this:
-                       result = EX_VAR(opline->result.var);
-                       switch (type) {
-                               case BP_VAR_R:
-                                       if (EXPECTED(Z_TYPE(EX(This)) == IS_OBJECT)) {
-                                               ZVAL_OBJ(result, Z_OBJ(EX(This)));
-                                               Z_ADDREF_P(result);
-                                       } else {
-                                               ZVAL_NULL(result);
-                                               zend_error(E_NOTICE,"Undefined variable: this");
-                                       }
-                                       break;
-                               case BP_VAR_IS:
-                                       if (EXPECTED(Z_TYPE(EX(This)) == IS_OBJECT)) {
-                                               ZVAL_OBJ(result, Z_OBJ(EX(This)));
-                                               Z_ADDREF_P(result);
-                                       } else {
-                                               ZVAL_NULL(result);
-                                       }
-                                       break;
-                               case BP_VAR_RW:
-                               case BP_VAR_W:
-                                       ZVAL_UNDEF(result);
-                                       zend_throw_error(NULL, "Cannot re-assign $this");
-                                       break;
-                               case BP_VAR_UNSET:
-                                       ZVAL_UNDEF(result);
-                                       zend_throw_error(NULL, "Cannot unset $this");
-                                       break;
-                               EMPTY_SWITCH_DEFAULT_CASE()
-                       }
+                       zend_fetch_this_var(type OPLINE_CC EXECUTE_DATA_CC);
                        if (IS_CONST != IS_CONST) {
                                zend_tmp_string_release(tmp_name);
                        }
                        ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
                }
-               switch (type) {
-                       case BP_VAR_R:
-                       case BP_VAR_UNSET:
-                               zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
-                               /* break missing intentionally */
-                       case BP_VAR_IS:
-                               retval = &EG(uninitialized_zval);
-                               break;
-                       case BP_VAR_RW:
-                               zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
+               if (type == BP_VAR_W) {
+                       retval = zend_hash_add_new(target_symbol_table, name, &EG(uninitialized_zval));
+               } else if (type == BP_VAR_IS) {
+                       retval = &EG(uninitialized_zval);
+               } else {
+                       zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
+                       if (type == BP_VAR_RW) {
                                retval = zend_hash_update(target_symbol_table, name, &EG(uninitialized_zval));
-                               break;
-                       case BP_VAR_W:
-                               retval = zend_hash_add_new(target_symbol_table, name, &EG(uninitialized_zval));
-                               break;
-                       EMPTY_SWITCH_DEFAULT_CASE()
+                       } else {
+                               retval = &EG(uninitialized_zval);
+                       }
                }
        /* GLOBAL or $$name variable may be an INDIRECT pointer to CV */
        } else if (Z_TYPE_P(retval) == IS_INDIRECT) {
@@ -8463,21 +8427,17 @@ fetch_this:
                        if (UNEXPECTED(zend_string_equals(name, ZSTR_KNOWN(ZEND_STR_THIS)))) {
                                goto fetch_this;
                        }
-                       switch (type) {
-                               case BP_VAR_R:
-                               case BP_VAR_UNSET:
-                                       zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
-                                       /* break missing intentionally */
-                               case BP_VAR_IS:
-                                       retval = &EG(uninitialized_zval);
-                                       break;
-                               case BP_VAR_RW:
-                                       zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
-                                       /* break missing intentionally */
-                               case BP_VAR_W:
+                       if (type == BP_VAR_W) {
+                               ZVAL_NULL(retval);
+                       } else if (type == BP_VAR_IS) {
+                               retval = &EG(uninitialized_zval);
+                       } else {
+                               zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
+                               if (type == BP_VAR_RW) {
                                        ZVAL_NULL(retval);
-                                       break;
-                               EMPTY_SWITCH_DEFAULT_CASE()
+                               } else {
+                                       retval = &EG(uninitialized_zval);
+                               }
                        }
                }
        }
@@ -16286,60 +16246,24 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_fetch_var_address_helper_SPEC_
        retval = zend_hash_find_ex(target_symbol_table, name, (IS_TMP_VAR|IS_VAR) == IS_CONST);
        if (retval == NULL) {
                if (UNEXPECTED(zend_string_equals(name, ZSTR_KNOWN(ZEND_STR_THIS)))) {
-                       zval *result;
-
 fetch_this:
-                       result = EX_VAR(opline->result.var);
-                       switch (type) {
-                               case BP_VAR_R:
-                                       if (EXPECTED(Z_TYPE(EX(This)) == IS_OBJECT)) {
-                                               ZVAL_OBJ(result, Z_OBJ(EX(This)));
-                                               Z_ADDREF_P(result);
-                                       } else {
-                                               ZVAL_NULL(result);
-                                               zend_error(E_NOTICE,"Undefined variable: this");
-                                       }
-                                       break;
-                               case BP_VAR_IS:
-                                       if (EXPECTED(Z_TYPE(EX(This)) == IS_OBJECT)) {
-                                               ZVAL_OBJ(result, Z_OBJ(EX(This)));
-                                               Z_ADDREF_P(result);
-                                       } else {
-                                               ZVAL_NULL(result);
-                                       }
-                                       break;
-                               case BP_VAR_RW:
-                               case BP_VAR_W:
-                                       ZVAL_UNDEF(result);
-                                       zend_throw_error(NULL, "Cannot re-assign $this");
-                                       break;
-                               case BP_VAR_UNSET:
-                                       ZVAL_UNDEF(result);
-                                       zend_throw_error(NULL, "Cannot unset $this");
-                                       break;
-                               EMPTY_SWITCH_DEFAULT_CASE()
-                       }
+                       zend_fetch_this_var(type OPLINE_CC EXECUTE_DATA_CC);
                        if ((IS_TMP_VAR|IS_VAR) != IS_CONST) {
                                zend_tmp_string_release(tmp_name);
                        }
                        ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
                }
-               switch (type) {
-                       case BP_VAR_R:
-                       case BP_VAR_UNSET:
-                               zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
-                               /* break missing intentionally */
-                       case BP_VAR_IS:
-                               retval = &EG(uninitialized_zval);
-                               break;
-                       case BP_VAR_RW:
-                               zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
+               if (type == BP_VAR_W) {
+                       retval = zend_hash_add_new(target_symbol_table, name, &EG(uninitialized_zval));
+               } else if (type == BP_VAR_IS) {
+                       retval = &EG(uninitialized_zval);
+               } else {
+                       zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
+                       if (type == BP_VAR_RW) {
                                retval = zend_hash_update(target_symbol_table, name, &EG(uninitialized_zval));
-                               break;
-                       case BP_VAR_W:
-                               retval = zend_hash_add_new(target_symbol_table, name, &EG(uninitialized_zval));
-                               break;
-                       EMPTY_SWITCH_DEFAULT_CASE()
+                       } else {
+                               retval = &EG(uninitialized_zval);
+                       }
                }
        /* GLOBAL or $$name variable may be an INDIRECT pointer to CV */
        } else if (Z_TYPE_P(retval) == IS_INDIRECT) {
@@ -16348,21 +16272,17 @@ fetch_this:
                        if (UNEXPECTED(zend_string_equals(name, ZSTR_KNOWN(ZEND_STR_THIS)))) {
                                goto fetch_this;
                        }
-                       switch (type) {
-                               case BP_VAR_R:
-                               case BP_VAR_UNSET:
-                                       zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
-                                       /* break missing intentionally */
-                               case BP_VAR_IS:
-                                       retval = &EG(uninitialized_zval);
-                                       break;
-                               case BP_VAR_RW:
-                                       zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
-                                       /* break missing intentionally */
-                               case BP_VAR_W:
+                       if (type == BP_VAR_W) {
+                               ZVAL_NULL(retval);
+                       } else if (type == BP_VAR_IS) {
+                               retval = &EG(uninitialized_zval);
+                       } else {
+                               zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
+                               if (type == BP_VAR_RW) {
                                        ZVAL_NULL(retval);
-                                       break;
-                               EMPTY_SWITCH_DEFAULT_CASE()
+                               } else {
+                                       retval = &EG(uninitialized_zval);
+                               }
                        }
                }
        }
@@ -46405,60 +46325,24 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_fetch_var_address_helper_SPEC_
        retval = zend_hash_find_ex(target_symbol_table, name, IS_CV == IS_CONST);
        if (retval == NULL) {
                if (UNEXPECTED(zend_string_equals(name, ZSTR_KNOWN(ZEND_STR_THIS)))) {
-                       zval *result;
-
 fetch_this:
-                       result = EX_VAR(opline->result.var);
-                       switch (type) {
-                               case BP_VAR_R:
-                                       if (EXPECTED(Z_TYPE(EX(This)) == IS_OBJECT)) {
-                                               ZVAL_OBJ(result, Z_OBJ(EX(This)));
-                                               Z_ADDREF_P(result);
-                                       } else {
-                                               ZVAL_NULL(result);
-                                               zend_error(E_NOTICE,"Undefined variable: this");
-                                       }
-                                       break;
-                               case BP_VAR_IS:
-                                       if (EXPECTED(Z_TYPE(EX(This)) == IS_OBJECT)) {
-                                               ZVAL_OBJ(result, Z_OBJ(EX(This)));
-                                               Z_ADDREF_P(result);
-                                       } else {
-                                               ZVAL_NULL(result);
-                                       }
-                                       break;
-                               case BP_VAR_RW:
-                               case BP_VAR_W:
-                                       ZVAL_UNDEF(result);
-                                       zend_throw_error(NULL, "Cannot re-assign $this");
-                                       break;
-                               case BP_VAR_UNSET:
-                                       ZVAL_UNDEF(result);
-                                       zend_throw_error(NULL, "Cannot unset $this");
-                                       break;
-                               EMPTY_SWITCH_DEFAULT_CASE()
-                       }
+                       zend_fetch_this_var(type OPLINE_CC EXECUTE_DATA_CC);
                        if (IS_CV != IS_CONST) {
                                zend_tmp_string_release(tmp_name);
                        }
                        ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
                }
-               switch (type) {
-                       case BP_VAR_R:
-                       case BP_VAR_UNSET:
-                               zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
-                               /* break missing intentionally */
-                       case BP_VAR_IS:
-                               retval = &EG(uninitialized_zval);
-                               break;
-                       case BP_VAR_RW:
-                               zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
+               if (type == BP_VAR_W) {
+                       retval = zend_hash_add_new(target_symbol_table, name, &EG(uninitialized_zval));
+               } else if (type == BP_VAR_IS) {
+                       retval = &EG(uninitialized_zval);
+               } else {
+                       zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
+                       if (type == BP_VAR_RW) {
                                retval = zend_hash_update(target_symbol_table, name, &EG(uninitialized_zval));
-                               break;
-                       case BP_VAR_W:
-                               retval = zend_hash_add_new(target_symbol_table, name, &EG(uninitialized_zval));
-                               break;
-                       EMPTY_SWITCH_DEFAULT_CASE()
+                       } else {
+                               retval = &EG(uninitialized_zval);
+                       }
                }
        /* GLOBAL or $$name variable may be an INDIRECT pointer to CV */
        } else if (Z_TYPE_P(retval) == IS_INDIRECT) {
@@ -46467,21 +46351,17 @@ fetch_this:
                        if (UNEXPECTED(zend_string_equals(name, ZSTR_KNOWN(ZEND_STR_THIS)))) {
                                goto fetch_this;
                        }
-                       switch (type) {
-                               case BP_VAR_R:
-                               case BP_VAR_UNSET:
-                                       zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
-                                       /* break missing intentionally */
-                               case BP_VAR_IS:
-                                       retval = &EG(uninitialized_zval);
-                                       break;
-                               case BP_VAR_RW:
-                                       zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
-                                       /* break missing intentionally */
-                               case BP_VAR_W:
+                       if (type == BP_VAR_W) {
+                               ZVAL_NULL(retval);
+                       } else if (type == BP_VAR_IS) {
+                               retval = &EG(uninitialized_zval);
+                       } else {
+                               zend_error(E_NOTICE,"Undefined variable: %s", ZSTR_VAL(name));
+                               if (type == BP_VAR_RW) {
                                        ZVAL_NULL(retval);
-                                       break;
-                               EMPTY_SWITCH_DEFAULT_CASE()
+                               } else {
+                                       retval = &EG(uninitialized_zval);
+                               }
                        }
                }
        }