]> granicus.if.org Git - php/commitdiff
Use fast comparison for (func->type == ZEND_USER_FUNCTION || func->type == ZEND_EVAL_...
authorDmitry Stogov <dmitry@zend.com>
Fri, 27 Jun 2014 09:02:49 +0000 (13:02 +0400)
committerDmitry Stogov <dmitry@zend.com>
Fri, 27 Jun 2014 09:02:49 +0000 (13:02 +0400)
Zend/zend_builtin_functions.c
Zend/zend_compile.h
Zend/zend_execute.c
Zend/zend_execute.h
Zend/zend_execute_API.c
Zend/zend_opcode.c
Zend/zend_vm_def.h

index 6b972897158ae468d2be2cfc998a23c881436f80..d084c564e71cd564602545d729fde13406dc1e0c 100644 (file)
@@ -2053,7 +2053,7 @@ ZEND_FUNCTION(debug_print_backtrace)
 
                skip = ptr;
                /* skip internal handler */
-               if ((!skip->func || (skip->func->common.type != ZEND_USER_FUNCTION && skip->func->common.type != ZEND_EVAL_CODE)) &&
+               if ((!skip->func || !ZEND_USER_CODE(skip->func->common.type)) &&
                    skip->prev_execute_data &&
                    skip->prev_execute_data->opline &&
                    skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL &&
@@ -2061,7 +2061,7 @@ ZEND_FUNCTION(debug_print_backtrace)
                        skip = skip->prev_execute_data;
                }
 
-               if (skip->func && (skip->func->common.type == ZEND_USER_FUNCTION || skip->func->common.type == ZEND_EVAL_CODE)) {
+               if (skip->func && ZEND_USER_CODE(skip->func->common.type)) {
                        filename = skip->func->op_array.filename->val;
                        lineno = skip->opline->lineno;
                } else {
@@ -2172,12 +2172,11 @@ ZEND_FUNCTION(debug_print_backtrace)
                        while (prev) {
                                if (prev->call &&
                                    prev->call->func &&
-                                       prev->call->func->common.type != ZEND_USER_FUNCTION &&
-                                       prev->call->func->common.type != ZEND_EVAL_CODE) {
+                                       !ZEND_USER_CODE(prev->call->func->common.type)) {
                                        prev = NULL;
                                        break;
                                }                                   
-                               if (prev->func && (prev->func->common.type == ZEND_USER_FUNCTION || prev->func->common.type == ZEND_EVAL_CODE)) {
+                               if (prev->func && ZEND_USER_CODE(prev->func->common.type)) {
                                        zend_printf(") called at [%s:%d]\n", prev->func->op_array.filename->val, prev->opline->lineno);
                                        break;
                                }
@@ -2230,7 +2229,7 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
 
                skip = ptr;
                /* skip internal handler */
-               if ((!skip->func || (skip->func->common.type != ZEND_USER_FUNCTION && skip->func->common.type != ZEND_EVAL_CODE)) &&
+               if ((!skip->func || !ZEND_USER_CODE(skip->func->common.type)) &&
                    skip->prev_execute_data &&
                    skip->prev_execute_data->opline &&
                    skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL &&
@@ -2238,7 +2237,7 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
                        skip = skip->prev_execute_data;
                }
 
-               if (skip->func && (skip->func->common.type == ZEND_USER_FUNCTION || skip->func->common.type == ZEND_EVAL_CODE)) {
+               if (skip->func && ZEND_USER_CODE(skip->func->common.type)) {
                        filename = skip->func->op_array.filename->val;
                        lineno = skip->opline->lineno;
                        add_assoc_string_ex(&stack_frame, "file", sizeof("file")-1, (char*)filename);
@@ -2253,13 +2252,12 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
                        while (prev) {
                                if (prev->call &&
                                    prev->call->func &&
-                                       prev->call->func->common.type != ZEND_USER_FUNCTION &&
-                                       prev->call->func->common.type != ZEND_EVAL_CODE &&
+                                       !ZEND_USER_CODE(prev->call->func->common.type) &&
                                        !(prev->call->func->common.type == ZEND_INTERNAL_FUNCTION &&
                                                (prev->call->func->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER))) {
                                        break;
                                }                                   
-                               if (prev->func && (prev->func->common.type == ZEND_USER_FUNCTION || prev->func->common.type == ZEND_EVAL_CODE)) {
+                               if (prev->func && ZEND_USER_CODE(prev->func->common.type)) {
 // TODO: we have to duplicate it, becaise it may be stored in opcache SHM ???
                                        add_assoc_str_ex(&stack_frame, "file", sizeof("file")-1, STR_DUP(prev->func->op_array.filename, 0));
                                        add_assoc_long_ex(&stack_frame, "line", sizeof("line")-1, prev->opline->lineno);
index 3bdf93d28467ccd1c99ca0fd4b8b11bca4db7fcc..1ccfd5bb0f647944e720e3ce3a47ac0bac6cc6ac 100644 (file)
@@ -761,6 +761,9 @@ int zend_add_literal(zend_op_array *op_array, zval *zv TSRMLS_DC);
 #define        ZEND_EVAL_CODE                                          4
 #define ZEND_OVERLOADED_FUNCTION_TEMPORARY     5
 
+/* A quick check (type == ZEND_USER_FUNCTION || type == ZEND_EVAL_CODE) */
+#define ZEND_USER_CODE(type) ((type & 1) == 0)
+
 #define ZEND_INTERNAL_CLASS         1
 #define ZEND_USER_CLASS             2
 
index 41ab9622274618958906cacc76301c31e49a75f3..7e94642aa8cdc5e1228a2a12b7546dcbc537fafc 100644 (file)
@@ -546,7 +546,7 @@ ZEND_API void zend_verify_arg_error(int error_type, const zend_function *zf, zen
                ZVAL_UNDEF(arg);
        }
 
-       if (ptr && ptr->func && (ptr->func->common.type == ZEND_USER_FUNCTION || ptr->func->common.type == ZEND_EVAL_CODE)) {
+       if (ptr && ptr->func && ZEND_USER_CODE(ptr->func->common.type)) {
                zend_error(error_type, "Argument %d passed to %s%s%s() must %s%s, %s%s given, called in %s on line %d and defined", arg_num, fclass, fsep, fname, need_msg, need_kind, given_msg, given_kind, ptr->func->op_array.filename->val, ptr->opline->lineno);
        } else {
                zend_error(error_type, "Argument %d passed to %s%s%s() must %s%s, %s%s given", arg_num, fclass, fsep, fname, need_msg, need_kind, given_msg, given_kind);
@@ -652,7 +652,7 @@ static void zend_verify_missing_arg(zend_execute_data *execute_data, zend_uint a
                const char *func_name = EX(func)->common.function_name ? EX(func)->common.function_name->val : "main";
                zend_execute_data *ptr = EX(prev_execute_data);
 
-               if (ptr && ptr->func && (ptr->func->common.type == ZEND_USER_FUNCTION || ptr->func->common.type == ZEND_EVAL_CODE)) {
+               if (ptr && ptr->func && ZEND_USER_CODE(ptr->func->common.type)) {
                        zend_error(E_WARNING, "Missing argument %u for %s%s%s(), called in %s on line %d and defined", arg_num, class_name, space, func_name, ptr->func->op_array.filename->val, ptr->opline->lineno);
                } else {
                        zend_error(E_WARNING, "Missing argument %u for %s%s%s()", arg_num, class_name, space, func_name);
index 095295f6984e624e8dd20d1ae11a1b6d15550fd5..b1e2166782d3fe82c53d34edf6099c2289f83bfc 100644 (file)
@@ -213,7 +213,7 @@ static zend_always_inline zend_execute_data *zend_vm_stack_push_call_frame(zend_
        int used_stack = ZEND_CALL_FRAME_SLOT + num_args;
        zend_execute_data *call;
        
-       if (func->type == ZEND_USER_FUNCTION || func->type == ZEND_EVAL_CODE) {
+       if (ZEND_USER_CODE(func->type)) {
                used_stack += func->op_array.last_var + func->op_array.T - MIN(func->op_array.num_args, num_args);
        }
        ZEND_VM_STACK_GROW_IF_NEEDED(used_stack);
index 92e0ede804c28f9db621be32697a734728063bb8..2ba582942ab7e58f7087db8e0bde00649983edf4 100644 (file)
@@ -1602,7 +1602,7 @@ ZEND_API void zend_rebuild_symbol_table(TSRMLS_D) /* {{{ */
 
                /* Search for last called user function */
                ex = EG(current_execute_data);
-               while (ex && (!ex->func || (ex->func->common.type != ZEND_USER_FUNCTION && ex->func->common.type != ZEND_EVAL_CODE))) {
+               while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->common.type))) {
                        ex = ex->prev_execute_data;
                }
                if (!ex) {
index 713d1e2c41aef1c70132cfac5e2d30c10ca73cdb..cad1dd2e9c09e425bb019caa7c56d97d3b7fc91a 100644 (file)
@@ -628,7 +628,7 @@ ZEND_API int pass_two(zend_op_array *op_array TSRMLS_DC)
 {
        zend_op *opline, *end;
 
-       if (op_array->type!=ZEND_USER_FUNCTION && op_array->type!=ZEND_EVAL_CODE) {
+       if (!ZEND_USER_CODE(op_array->type)) {
                return 0;
        }
        if (op_array->has_finally_block) {
index 433f8133a617c07915acf6bbc7a88f986afddc84..2faed6b395d6a44098c67dc3fe6e9fd2146f1cdc 100644 (file)
@@ -1858,7 +1858,7 @@ ZEND_VM_HELPER(zend_leave_helper, ANY, ANY)
                        zend_detach_symbol_table(execute_data);
                        old_execute_data = EX(prev_execute_data);
                        while (old_execute_data) {
-                               if (old_execute_data->func && (old_execute_data->func->op_array.type == ZEND_USER_FUNCTION || old_execute_data->func->op_array.type == ZEND_EVAL_CODE)) {
+                               if (old_execute_data->func && ZEND_USER_CODE(old_execute_data->func->op_array.type)) {
                                        if (old_execute_data->symbol_table == symbol_table) {
                                                zend_attach_symbol_table(old_execute_data);
                                        }