Skip to content

Commit c3d17c7

Browse files
committed
Simplify
1 parent c94993d commit c3d17c7

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

Zend/zend_ast.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -993,9 +993,7 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_inner(
993993
}
994994
case ZEND_AST_CLOSURE_CONSTEXPR:
995995
{
996-
zend_ast *child = ast->child[0];
997-
zval *z = zend_ast_get_zval(child);
998-
zend_function *func = Z_PTR_P(z);
996+
zend_function *func = Z_PTR_P(&((zend_ast_zval*)(ast))->val);
999997

1000998
zend_create_closure(result, func, scope, scope, NULL);
1001999
return SUCCESS;
@@ -1079,7 +1077,7 @@ static size_t ZEND_FASTCALL zend_ast_tree_size(zend_ast *ast)
10791077
{
10801078
size_t size;
10811079

1082-
if (ast->kind == ZEND_AST_ZVAL || ast->kind == ZEND_AST_CONSTANT) {
1080+
if (ast->kind == ZEND_AST_ZVAL || ast->kind == ZEND_AST_CONSTANT || ast->kind == ZEND_AST_CLOSURE_CONSTEXPR) {
10831081
size = sizeof(zend_ast_zval);
10841082
} else if (zend_ast_is_list(ast)) {
10851083
uint32_t i;
@@ -1106,7 +1104,14 @@ static size_t ZEND_FASTCALL zend_ast_tree_size(zend_ast *ast)
11061104

11071105
static void* ZEND_FASTCALL zend_ast_tree_copy(zend_ast *ast, void *buf)
11081106
{
1109-
if (ast->kind == ZEND_AST_ZVAL) {
1107+
if (ast->kind == ZEND_AST_CLOSURE_CONSTEXPR) {
1108+
zend_ast_zval *new = (zend_ast_zval*)buf;
1109+
new->kind = ZEND_AST_CLOSURE_CONSTEXPR;
1110+
new->attr = ast->attr;
1111+
ZVAL_COPY(&new->val, &((zend_ast_zval *) ast)->val);
1112+
Z_LINENO(new->val) = zend_ast_get_lineno(ast);
1113+
buf = (void*)((char*)buf + sizeof(zend_ast_zval));
1114+
} else if (ast->kind == ZEND_AST_ZVAL) {
11101115
zend_ast_zval *new = (zend_ast_zval*)buf;
11111116
new->kind = ZEND_AST_ZVAL;
11121117
new->attr = ast->attr;
@@ -1187,6 +1192,8 @@ ZEND_API void ZEND_FASTCALL zend_ast_destroy(zend_ast *ast)
11871192
goto tail_call;
11881193
} else if (EXPECTED(ast->kind == ZEND_AST_ZVAL)) {
11891194
zval_ptr_dtor_nogc(zend_ast_get_zval(ast));
1195+
} else if (EXPECTED(ast->kind == ZEND_AST_CLOSURE_CONSTEXPR)) {
1196+
zval_ptr_dtor_nogc(&((zend_ast_zval*)(ast))->val);
11901197
} else if (EXPECTED(zend_ast_is_list(ast))) {
11911198
zend_ast_list *list = zend_ast_get_list(ast);
11921199
if (list->children) {

Zend/zend_ast.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
enum _zend_ast_kind {
3535
/* special nodes */
3636
ZEND_AST_ZVAL = 1 << ZEND_AST_SPECIAL_SHIFT,
37+
ZEND_AST_CLOSURE_CONSTEXPR,
3738
ZEND_AST_CONSTANT,
3839
ZEND_AST_ZNODE,
3940

@@ -111,8 +112,6 @@ enum _zend_ast_kind {
111112
ZEND_AST_CONTINUE,
112113
ZEND_AST_PROPERTY_HOOK_SHORT_BODY,
113114

114-
ZEND_AST_CLOSURE_CONSTEXPR,
115-
116115
/* 2 child nodes */
117116
ZEND_AST_DIM = 2 << ZEND_AST_NUM_CHILDREN_SHIFT,
118117
ZEND_AST_PROP,

Zend/zend_compile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11184,7 +11184,8 @@ static void zend_compile_const_expr_closure(zend_ast **ast_ptr)
1118411184
zend_ast_destroy(*ast_ptr);
1118511185
zval z;
1118611186
ZVAL_PTR(&z, op);
11187-
*ast_ptr = zend_ast_create(ZEND_AST_CLOSURE_CONSTEXPR, zend_ast_create_zval(&z));
11187+
*ast_ptr = zend_ast_create_zval(&z);
11188+
(*ast_ptr)->kind = ZEND_AST_CLOSURE_CONSTEXPR;
1118811189
}
1118911190

1119011191
static void zend_compile_const_expr_args(zend_ast **ast_ptr)

ext/opcache/zend_persist.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ static zend_ast *zend_persist_ast(zend_ast *ast)
177177
zend_ast *node;
178178

179179
if (ast->kind == ZEND_AST_CLOSURE_CONSTEXPR) {
180-
uint32_t children = zend_ast_get_num_children(ast);
181-
node = zend_shared_memdup(ast, zend_ast_size(children));
182-
zend_persist_op_array(zend_ast_get_zval(node->child[0]));
180+
zend_ast_zval *copy = zend_shared_memdup(ast, sizeof(zend_ast_zval));
181+
zend_persist_op_array(&copy->val);
182+
node = (zend_ast *) copy;
183183
} else if (ast->kind == ZEND_AST_ZVAL || ast->kind == ZEND_AST_CONSTANT) {
184184
zend_ast_zval *copy = zend_shared_memdup(ast, sizeof(zend_ast_zval));
185185
zend_persist_zval(&copy->val);

ext/opcache/zend_persist_calc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static void zend_persist_ast_calc(zend_ast *ast)
7979

8080
if (ast->kind == ZEND_AST_CLOSURE_CONSTEXPR) {
8181
ADD_SIZE(sizeof(zend_ast_zval));
82-
zend_persist_op_array_calc(zend_ast_get_zval(ast->child[0]));
82+
zend_persist_op_array_calc(&((zend_ast_zval*)(ast))->val);
8383
} else if (ast->kind == ZEND_AST_ZVAL || ast->kind == ZEND_AST_CONSTANT) {
8484
ADD_SIZE(sizeof(zend_ast_zval));
8585
zend_persist_zval_calc(&((zend_ast_zval*)(ast))->val);

0 commit comments

Comments
 (0)