Skip to content

Commit cebb5cd

Browse files
committed
micro-optimization
1 parent 58c083d commit cebb5cd

File tree

2 files changed

+98
-72
lines changed

2 files changed

+98
-72
lines changed

Zend/zend_vm_def.h

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,56 +2503,69 @@ ZEND_VM_HELPER(zend_leave_helper, ANY, ANY)
25032503
zend_execute_data *old_execute_data;
25042504
uint32_t call_info = EX_CALL_INFO();
25052505

2506-
if (EXPECTED((call_info & (ZEND_CALL_CODE|ZEND_CALL_TOP)) == 0)) {
2506+
if (EXPECTED((call_info & (ZEND_CALL_CODE|ZEND_CALL_TOP|ZEND_CALL_HAS_SYMBOL_TABLE|ZEND_CALL_FREE_EXTRA_ARGS|ZEND_CALL_ALLOCATED)) == 0)) {
25072507
i_free_compiled_variables(execute_data);
2508-
if (UNEXPECTED(call_info & (ZEND_CALL_HAS_SYMBOL_TABLE|ZEND_CALL_FREE_EXTRA_ARGS|ZEND_CALL_ALLOCATED))) {
2509-
if (UNEXPECTED(call_info & ZEND_CALL_HAS_SYMBOL_TABLE)) {
2510-
zend_clean_and_cache_symbol_table(EX(symbol_table));
2511-
}
2512-
EG(current_execute_data) = EX(prev_execute_data);
2513-
if (UNEXPECTED(call_info & ZEND_CALL_RELEASE_THIS)) {
2514-
zend_object *object = Z_OBJ(execute_data->This);
2508+
2509+
EG(current_execute_data) = EX(prev_execute_data);
2510+
if (UNEXPECTED(call_info & ZEND_CALL_RELEASE_THIS)) {
2511+
zend_object *object = Z_OBJ(execute_data->This);
25152512
#if 0
2516-
if (UNEXPECTED(EG(exception) != NULL) && (EX(opline)->op1.num & ZEND_CALL_CTOR)) {
2513+
if (UNEXPECTED(EG(exception) != NULL) && (EX(opline)->op1.num & ZEND_CALL_CTOR)) {
25172514
#else
2518-
if (UNEXPECTED(EG(exception) != NULL) && (call_info & ZEND_CALL_CTOR)) {
2515+
if (UNEXPECTED(EG(exception) != NULL) && (call_info & ZEND_CALL_CTOR)) {
25192516
#endif
2520-
GC_REFCOUNT(object)--;
2521-
if (GC_REFCOUNT(object) == 1) {
2522-
zend_object_store_ctor_failed(object);
2523-
}
2517+
GC_REFCOUNT(object)--;
2518+
if (GC_REFCOUNT(object) == 1) {
2519+
zend_object_store_ctor_failed(object);
25242520
}
2525-
OBJ_RELEASE(object);
2526-
} else if (UNEXPECTED(call_info & ZEND_CALL_CLOSURE)) {
2527-
OBJ_RELEASE((zend_object*)execute_data->func->op_array.prototype);
25282521
}
2522+
OBJ_RELEASE(object);
2523+
} else if (UNEXPECTED(call_info & ZEND_CALL_CLOSURE)) {
2524+
OBJ_RELEASE((zend_object*)execute_data->func->op_array.prototype);
2525+
}
2526+
EG(vm_stack_top) = (zval*)execute_data;
2527+
execute_data = EX(prev_execute_data);
25292528

2530-
zend_vm_stack_free_extra_args_ex(call_info, execute_data);
2531-
old_execute_data = execute_data;
2532-
execute_data = EX(prev_execute_data);
2533-
zend_vm_stack_free_call_frame_ex(call_info, old_execute_data);
2534-
} else {
2535-
EG(current_execute_data) = EX(prev_execute_data);
2536-
if (UNEXPECTED(call_info & ZEND_CALL_RELEASE_THIS)) {
2537-
zend_object *object = Z_OBJ(execute_data->This);
2529+
if (UNEXPECTED(EG(exception) != NULL)) {
2530+
const zend_op *old_opline = EX(opline);
2531+
zend_throw_exception_internal(NULL);
2532+
if (RETURN_VALUE_USED(old_opline)) {
2533+
zval_ptr_dtor(EX_VAR(old_opline->result.var));
2534+
}
2535+
HANDLE_EXCEPTION_LEAVE();
2536+
}
2537+
2538+
LOAD_NEXT_OPLINE();
2539+
ZEND_VM_LEAVE();
2540+
} else if (EXPECTED((call_info & (ZEND_CALL_CODE|ZEND_CALL_TOP)) == 0)) {
2541+
i_free_compiled_variables(execute_data);
2542+
2543+
if (UNEXPECTED(call_info & ZEND_CALL_HAS_SYMBOL_TABLE)) {
2544+
zend_clean_and_cache_symbol_table(EX(symbol_table));
2545+
}
2546+
EG(current_execute_data) = EX(prev_execute_data);
2547+
if (UNEXPECTED(call_info & ZEND_CALL_RELEASE_THIS)) {
2548+
zend_object *object = Z_OBJ(execute_data->This);
25382549
#if 0
2539-
if (UNEXPECTED(EG(exception) != NULL) && (EX(opline)->op1.num & ZEND_CALL_CTOR)) {
2550+
if (UNEXPECTED(EG(exception) != NULL) && (EX(opline)->op1.num & ZEND_CALL_CTOR)) {
25402551
#else
2541-
if (UNEXPECTED(EG(exception) != NULL) && (call_info & ZEND_CALL_CTOR)) {
2552+
if (UNEXPECTED(EG(exception) != NULL) && (call_info & ZEND_CALL_CTOR)) {
25422553
#endif
2543-
GC_REFCOUNT(object)--;
2544-
if (GC_REFCOUNT(object) == 1) {
2545-
zend_object_store_ctor_failed(object);
2546-
}
2554+
GC_REFCOUNT(object)--;
2555+
if (GC_REFCOUNT(object) == 1) {
2556+
zend_object_store_ctor_failed(object);
25472557
}
2548-
OBJ_RELEASE(object);
2549-
} else if (UNEXPECTED(call_info & ZEND_CALL_CLOSURE)) {
2550-
OBJ_RELEASE((zend_object*)execute_data->func->op_array.prototype);
25512558
}
2552-
EG(vm_stack_top) = (zval*)execute_data;
2553-
execute_data = EX(prev_execute_data);
2559+
OBJ_RELEASE(object);
2560+
} else if (UNEXPECTED(call_info & ZEND_CALL_CLOSURE)) {
2561+
OBJ_RELEASE((zend_object*)execute_data->func->op_array.prototype);
25542562
}
25552563

2564+
zend_vm_stack_free_extra_args_ex(call_info, execute_data);
2565+
old_execute_data = execute_data;
2566+
execute_data = EX(prev_execute_data);
2567+
zend_vm_stack_free_call_frame_ex(call_info, old_execute_data);
2568+
25562569
if (UNEXPECTED(EG(exception) != NULL)) {
25572570
const zend_op *old_opline = EX(opline);
25582571
zend_throw_exception_internal(NULL);

Zend/zend_vm_execute.h

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -477,56 +477,69 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_leave_helper_SPEC(ZEND_OPCODE_
477477
zend_execute_data *old_execute_data;
478478
uint32_t call_info = EX_CALL_INFO();
479479

480-
if (EXPECTED((call_info & (ZEND_CALL_CODE|ZEND_CALL_TOP)) == 0)) {
480+
if (EXPECTED((call_info & (ZEND_CALL_CODE|ZEND_CALL_TOP|ZEND_CALL_HAS_SYMBOL_TABLE|ZEND_CALL_FREE_EXTRA_ARGS|ZEND_CALL_ALLOCATED)) == 0)) {
481481
i_free_compiled_variables(execute_data);
482-
if (UNEXPECTED(call_info & (ZEND_CALL_HAS_SYMBOL_TABLE|ZEND_CALL_FREE_EXTRA_ARGS|ZEND_CALL_ALLOCATED))) {
483-
if (UNEXPECTED(call_info & ZEND_CALL_HAS_SYMBOL_TABLE)) {
484-
zend_clean_and_cache_symbol_table(EX(symbol_table));
485-
}
486-
EG(current_execute_data) = EX(prev_execute_data);
487-
if (UNEXPECTED(call_info & ZEND_CALL_RELEASE_THIS)) {
488-
zend_object *object = Z_OBJ(execute_data->This);
482+
483+
EG(current_execute_data) = EX(prev_execute_data);
484+
if (UNEXPECTED(call_info & ZEND_CALL_RELEASE_THIS)) {
485+
zend_object *object = Z_OBJ(execute_data->This);
489486
#if 0
490-
if (UNEXPECTED(EG(exception) != NULL) && (EX(opline)->op1.num & ZEND_CALL_CTOR)) {
487+
if (UNEXPECTED(EG(exception) != NULL) && (EX(opline)->op1.num & ZEND_CALL_CTOR)) {
491488
#else
492-
if (UNEXPECTED(EG(exception) != NULL) && (call_info & ZEND_CALL_CTOR)) {
489+
if (UNEXPECTED(EG(exception) != NULL) && (call_info & ZEND_CALL_CTOR)) {
493490
#endif
494-
GC_REFCOUNT(object)--;
495-
if (GC_REFCOUNT(object) == 1) {
496-
zend_object_store_ctor_failed(object);
497-
}
491+
GC_REFCOUNT(object)--;
492+
if (GC_REFCOUNT(object) == 1) {
493+
zend_object_store_ctor_failed(object);
498494
}
499-
OBJ_RELEASE(object);
500-
} else if (UNEXPECTED(call_info & ZEND_CALL_CLOSURE)) {
501-
OBJ_RELEASE((zend_object*)execute_data->func->op_array.prototype);
502495
}
496+
OBJ_RELEASE(object);
497+
} else if (UNEXPECTED(call_info & ZEND_CALL_CLOSURE)) {
498+
OBJ_RELEASE((zend_object*)execute_data->func->op_array.prototype);
499+
}
500+
EG(vm_stack_top) = (zval*)execute_data;
501+
execute_data = EX(prev_execute_data);
503502

504-
zend_vm_stack_free_extra_args_ex(call_info, execute_data);
505-
old_execute_data = execute_data;
506-
execute_data = EX(prev_execute_data);
507-
zend_vm_stack_free_call_frame_ex(call_info, old_execute_data);
508-
} else {
509-
EG(current_execute_data) = EX(prev_execute_data);
510-
if (UNEXPECTED(call_info & ZEND_CALL_RELEASE_THIS)) {
511-
zend_object *object = Z_OBJ(execute_data->This);
503+
if (UNEXPECTED(EG(exception) != NULL)) {
504+
const zend_op *old_opline = EX(opline);
505+
zend_throw_exception_internal(NULL);
506+
if (RETURN_VALUE_USED(old_opline)) {
507+
zval_ptr_dtor(EX_VAR(old_opline->result.var));
508+
}
509+
HANDLE_EXCEPTION_LEAVE();
510+
}
511+
512+
LOAD_NEXT_OPLINE();
513+
ZEND_VM_LEAVE();
514+
} else if (EXPECTED((call_info & (ZEND_CALL_CODE|ZEND_CALL_TOP)) == 0)) {
515+
i_free_compiled_variables(execute_data);
516+
517+
if (UNEXPECTED(call_info & ZEND_CALL_HAS_SYMBOL_TABLE)) {
518+
zend_clean_and_cache_symbol_table(EX(symbol_table));
519+
}
520+
EG(current_execute_data) = EX(prev_execute_data);
521+
if (UNEXPECTED(call_info & ZEND_CALL_RELEASE_THIS)) {
522+
zend_object *object = Z_OBJ(execute_data->This);
512523
#if 0
513-
if (UNEXPECTED(EG(exception) != NULL) && (EX(opline)->op1.num & ZEND_CALL_CTOR)) {
524+
if (UNEXPECTED(EG(exception) != NULL) && (EX(opline)->op1.num & ZEND_CALL_CTOR)) {
514525
#else
515-
if (UNEXPECTED(EG(exception) != NULL) && (call_info & ZEND_CALL_CTOR)) {
526+
if (UNEXPECTED(EG(exception) != NULL) && (call_info & ZEND_CALL_CTOR)) {
516527
#endif
517-
GC_REFCOUNT(object)--;
518-
if (GC_REFCOUNT(object) == 1) {
519-
zend_object_store_ctor_failed(object);
520-
}
528+
GC_REFCOUNT(object)--;
529+
if (GC_REFCOUNT(object) == 1) {
530+
zend_object_store_ctor_failed(object);
521531
}
522-
OBJ_RELEASE(object);
523-
} else if (UNEXPECTED(call_info & ZEND_CALL_CLOSURE)) {
524-
OBJ_RELEASE((zend_object*)execute_data->func->op_array.prototype);
525532
}
526-
EG(vm_stack_top) = (zval*)execute_data;
527-
execute_data = EX(prev_execute_data);
533+
OBJ_RELEASE(object);
534+
} else if (UNEXPECTED(call_info & ZEND_CALL_CLOSURE)) {
535+
OBJ_RELEASE((zend_object*)execute_data->func->op_array.prototype);
528536
}
529537

538+
zend_vm_stack_free_extra_args_ex(call_info, execute_data);
539+
old_execute_data = execute_data;
540+
execute_data = EX(prev_execute_data);
541+
zend_vm_stack_free_call_frame_ex(call_info, old_execute_data);
542+
530543
if (UNEXPECTED(EG(exception) != NULL)) {
531544
const zend_op *old_opline = EX(opline);
532545
zend_throw_exception_internal(NULL);

0 commit comments

Comments
 (0)