Skip to content

Commit 02eded8

Browse files
committed
Avoid function copying
1 parent e42e8b1 commit 02eded8

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

Zend/zend_compile.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,21 +1057,21 @@ ZEND_API int do_bind_function(zval *lcname) /* {{{ */
10571057

10581058
rtd_key = lcname + 1;
10591059
zv = zend_hash_find_ex(EG(function_table), Z_STR_P(rtd_key), 1);
1060-
function = (zend_function*)Z_PTR_P(zv);
1061-
new_function = zend_arena_alloc(&CG(arena), sizeof(zend_op_array));
1062-
memcpy(new_function, function, sizeof(zend_op_array));
1063-
if (zend_hash_add_ptr(EG(function_table), Z_STR_P(lcname), new_function) == NULL) {
1064-
do_bind_function_error(Z_STR_P(lcname), &new_function->op_array, 0);
1065-
return FAILURE;
1066-
} else {
1060+
new_function = function = (zend_function*)Z_PTR_P(zv);
1061+
if (function->op_array.static_variables
1062+
&& !(function->op_array.fn_flags & ZEND_ACC_IMMUTABLE)) {
1063+
new_function = zend_arena_alloc(&CG(arena), sizeof(zend_op_array));
1064+
memcpy(new_function, function, sizeof(zend_op_array));
1065+
function->op_array.static_variables = NULL; /* NULL out the unbound function */
10671066
if (function->op_array.refcount) {
10681067
(*function->op_array.refcount)++;
10691068
}
1070-
if (!(function->op_array.fn_flags & ZEND_ACC_IMMUTABLE)) {
1071-
function->op_array.static_variables = NULL; /* NULL out the unbound function */
1072-
}
1073-
return SUCCESS;
10741069
}
1070+
if (UNEXPECTED(zend_hash_add_ptr(EG(function_table), Z_STR_P(lcname), new_function) == NULL)) {
1071+
do_bind_function_error(Z_STR_P(lcname), &new_function->op_array, 0);
1072+
return FAILURE;
1073+
}
1074+
return SUCCESS;
10751075
}
10761076
/* }}} */
10771077

0 commit comments

Comments
 (0)