]> granicus.if.org Git - php/commitdiff
Make ast->children a uint
authorNikita Popov <nikic@php.net>
Thu, 19 Jun 2014 11:08:21 +0000 (13:08 +0200)
committerNikita Popov <nikic@php.net>
Thu, 19 Jun 2014 11:48:50 +0000 (13:48 +0200)
Future optimization: only use uint for dynamic lists and use a
uchar or even an introspection function to get the child count.

Zend/zend_ast.c
Zend/zend_ast.h
Zend/zend_compile.h

index ba0b57fccc7431567f9d96afd954af9e1c4c0e87..9a795599fe5ce4a6eaca422a61200ee098cf4d62 100644 (file)
@@ -27,7 +27,7 @@ ZEND_API zend_ast *zend_ast_create_constant(zval *zv)
 {
        zend_ast_zval *ast = emalloc(sizeof(zend_ast_zval));
        ast->kind = ZEND_CONST;
-       ast->children = 0;
+       ast->EA = 0;
        ZVAL_COPY_VALUE(&ast->val, zv);
        return (zend_ast *) ast;
 }
@@ -36,7 +36,7 @@ ZEND_API zend_ast *zend_ast_create_znode(znode *node)
 {
        zend_ast_znode *ast = emalloc(sizeof(zend_ast_znode));
        ast->kind = ZEND_AST_ZNODE;
-       ast->children = 0;
+       ast->EA = 0;
        ast->node = *node;
        return (zend_ast *) ast;
 }
@@ -45,6 +45,7 @@ ZEND_API zend_ast* zend_ast_create_unary(uint kind, zend_ast *op0)
 {
        zend_ast *ast = emalloc(sizeof(zend_ast));
        ast->kind = kind;
+       ast->EA = 0;
        ast->children = 1;
        ast->child[0] = op0;
        return ast;
@@ -54,6 +55,7 @@ ZEND_API zend_ast* zend_ast_create_binary(uint kind, zend_ast *op0, zend_ast *op
 {
        zend_ast *ast = emalloc(sizeof(zend_ast) + sizeof(zend_ast *));
        ast->kind = kind;
+       ast->EA = 0;
        ast->children = 2;
        ast->child[0] = op0;
        ast->child[1] = op1;
@@ -64,6 +66,7 @@ ZEND_API zend_ast* zend_ast_create_ternary(uint kind, zend_ast *op0, zend_ast *o
 {
        zend_ast *ast = emalloc(sizeof(zend_ast) + sizeof(zend_ast *) * 2);
        ast->kind = kind;
+       ast->EA = 0;
        ast->children = 3;
        ast->child[0] = op0;
        ast->child[1] = op1;
@@ -76,6 +79,7 @@ ZEND_API zend_ast *zend_ast_create_dynamic(uint kind)
        /* use 4 children as default */
        zend_ast *ast = emalloc(sizeof(zend_ast) + sizeof(zend_ast *) * 3);
        ast->kind = kind;
+       ast->EA = 0;
        ast->children = 0;
        return ast;
 }
@@ -396,7 +400,7 @@ ZEND_API void zend_ast_destroy(zend_ast *ast)
 
        if (ast->kind == ZEND_CONST) {
                zval_dtor(zend_ast_get_zval(ast));
-       } else {
+       } else if (ast->kind != ZEND_AST_ZNODE) {
                for (i = 0; i < ast->children; i++) {
                        if (ast->child[i]) {
                                zend_ast_destroy(ast->child[i]);
index c89b82c84e8736668c7d6dcbe89761ffc88fcfcf..cceb3b0f8f0cee3b78c20374c42ee6e5fd251944 100644 (file)
@@ -75,13 +75,14 @@ typedef enum _zend_ast_kind {
 
 struct _zend_ast {
        unsigned short kind;
-       unsigned short children;
+       unsigned short EA;
+       zend_uint children;
        zend_ast *child[1];
 };
 
 typedef struct _zend_ast_zval {
        unsigned short kind;
-       unsigned short children;
+       unsigned short EA;
        zval val;
 } zend_ast_zval;
 
index bbf2bc7274f6d465901e9a4ecb8c4d442a70e6c5..6dfa74f023022b022ca5d2e6d0dd000130d0f47d 100644 (file)
@@ -90,7 +90,7 @@ typedef struct _znode { /* used only during compilation */
 /* Temporarily defined here, to avoid header ordering issues */
 typedef struct _zend_ast_znode {
        unsigned short kind;
-       unsigned short children;
+       unsigned short EA;
        znode node;
 } zend_ast_znode;
 ZEND_API zend_ast *zend_ast_create_znode(znode *node);