Skip to content
Permalink
Browse files

Fixed issue #1743: Check ZEND_ACC_CLOSURE flag instead of string comp…

…arison

Check fn_flags & ZEND_ACC_CLOSURE instead of a string match, should be much
faster as this is in the critical path of xdebug_add_stack_frame.
  • Loading branch information
beberlei authored and derickr committed Feb 8, 2020
1 parent cfcd568 commit 1f2bdcffdf080a74b250089c1b2d621ef62ca077
Showing with 2 additions and 19 deletions.
  1. +2 −18 src/base/stack.c
  2. +0 −1 src/base/stack.h
@@ -863,22 +863,6 @@ static int find_line_number_for_current_execute_point(zend_execute_data *edata)
return 0;
}

int xdebug_function_name_is_closure(char *fname)
{
int length = strlen(fname);
int closure_length = strlen("{closure}");

if (length < closure_length) {
return 0;
}

if (strcmp(fname + length - closure_length, "{closure}") == 0) {
return 1;
}

return 0;
}

char* xdebug_wrap_closure_location_around_function_name(zend_op_array *opa, char *fname)
{
xdebug_str tmp = XDEBUG_STR_INITIALIZER;
@@ -922,7 +906,7 @@ void xdebug_build_fname_from_oparray(xdebug_func *tmp, zend_op_array *opa)
memset(tmp, 0, sizeof(xdebug_func));

if (opa->function_name) {
if (xdebug_function_name_is_closure(STR_NAME_VAL(opa->function_name))) {
if (opa->fn_flags & ZEND_ACC_CLOSURE) {
tmp->function = xdebug_wrap_closure_location_around_function_name(opa, STR_NAME_VAL(opa->function_name));
closure = 1;
} else {
@@ -969,7 +953,7 @@ void xdebug_build_fname(xdebug_func *tmp, zend_execute_data *edata)
}
}
if (edata->func->common.function_name) {
if (xdebug_function_name_is_closure(edata->func->common.function_name->val)) {
if (edata->func->common.fn_flags & ZEND_ACC_CLOSURE) {
tmp->function = xdebug_wrap_closure_location_around_function_name(&edata->func->op_array, edata->func->common.function_name->val);
} else if (strncmp(edata->func->common.function_name->val, "call_user_func", 14) == 0) {
const char *fname = NULL;
@@ -23,7 +23,6 @@

#define XDEBUG_STACK_NO_DESC 0x01

int xdebug_function_name_is_closure(char *fname);
char* xdebug_wrap_closure_location_around_function_name(zend_op_array *opa, char *fname);
void xdebug_func_dtor_by_ref(xdebug_func *elem); /* TODO: Remove this API */
void xdebug_func_dtor(xdebug_func *elem);

0 comments on commit 1f2bdcf

Please sign in to comment.
You can’t perform that action at this time.