com php-src: Use fast comparison for (func->type == ZEND _USER_FUNCTION || func->type == ZEND_EV AL_CODE): Zend/zend_builtin_functions.c Zend/ze
nd_compile.h Zend/zend_execute.c Zend/zend_execut e.h Zend/zend_execute_API.c Zend/zend_opcode.c Zend/zend_vm_def.h
| From: | Dmitry Stogov | Date: | Fri, 27 Jun 2014 09:02:49 +0000 |
| Subject: | com php-src: Use fast comparison for (func->type == ZEND _USER_FUNCTION || func->type == ZEND_EV AL_CODE): Zend/zend_builtin_functions.c Zend/ze nd_compile.h Zend/zend_execute.c Zend/zend_execut e.h Zend/zend_execute_API.c Zend/zend_opcode.c Zend/zend_vm_def.h |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-79283@lists.php.net to get a copy of this message | ||
Commit: d6bd21eab2ad5beaab248851e3a5cef9cdb24b5c
Author: Dmitry Stogov <dmitry@zend.com> Fri, 27 Jun 2014 13:02:49 +0400
Parents: 032f33591a643c0cabe615a016b8f79f2fd9b277
Branches: phpng
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d6bd21eab2ad5beaab248851e3a5cef9cdb24b5c
Log:
Use fast comparison for (func->type == ZEND_USER_FUNCTION || func->type == ZEND_EVAL_CODE)
Changed paths:
M Zend/zend_builtin_functions.c
M Zend/zend_compile.h
M Zend/zend_execute.c
M Zend/zend_execute.h
M Zend/zend_execute_API.c
M Zend/zend_opcode.c
M Zend/zend_vm_def.h
Diff:
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index 6b97289..d084c56 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -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);
diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h
index 3bdf93d..1ccfd5b 100644
--- a/Zend/zend_compile.h
+++ b/Zend/zend_compile.h
@@ -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
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index 41ab962..7e94642 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -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);
diff --git a/Zend/zend_execute.h b/Zend/zend_execute.h
index 095295f..b1e2166 100644
--- a/Zend/zend_execute.h
+++ b/Zend/zend_execute.h
@@ -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);
diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c
index 92e0ede..2ba5829 100644
--- a/Zend/zend_execute_API.c
+++ b/Zend/zend_execute_API.c
@@ -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) {
diff --git a/Zend/zend_opcode.c b/Zend/zend_opcode.c
index 713d1e2..cad1dd2 100644
--- a/Zend/zend_opcode.c
+++ b/Zend/zend_opcode.c
@@ -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) {
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index 433f813..2faed6b 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -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);
}