summaryrefslogtreecommitdiff
path: root/ext/opcache
diff options
context:
space:
mode:
Diffstat (limited to 'ext/opcache')
-rw-r--r--ext/opcache/Optimizer/optimize_func_calls.c8
-rw-r--r--ext/opcache/Optimizer/pass1_5.c4
-rw-r--r--ext/opcache/zend_accelerator_util_funcs.c50
-rw-r--r--ext/opcache/zend_persist.c29
-rw-r--r--ext/opcache/zend_persist_calc.c25
5 files changed, 79 insertions, 37 deletions
diff --git a/ext/opcache/Optimizer/optimize_func_calls.c b/ext/opcache/Optimizer/optimize_func_calls.c
index b93fc3667c..9e3ed290bd 100644
--- a/ext/opcache/Optimizer/optimize_func_calls.c
+++ b/ext/opcache/Optimizer/optimize_func_calls.c
@@ -3,6 +3,10 @@
*/
#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
+#define ZEND_OP2_IS_CONST_STRING(opline) \
+ (ZEND_OP2_TYPE(opline) == IS_CONST && \
+ Z_TYPE(op_array->literals[(opline)->op2.constant]) == IS_STRING)
+
typedef struct _optimizer_call_info {
zend_function *func;
zend_op *opline;
@@ -25,7 +29,7 @@ static void optimize_func_calls(zend_op_array *op_array, zend_optimizer_ctx *ctx
switch (opline->opcode) {
case ZEND_INIT_FCALL_BY_NAME:
case ZEND_INIT_NS_FCALL_BY_NAME:
- if (ZEND_OP2_TYPE(opline) == IS_CONST) {
+ if (ZEND_OP2_IS_CONST_STRING(opline)) {
zend_function *func;
zval *function_name = &op_array->literals[opline->op2.constant + 1];
if ((func = zend_hash_find_ptr(&ctx->script->function_table,
@@ -64,7 +68,7 @@ static void optimize_func_calls(zend_op_array *op_array, zend_optimizer_ctx *ctx
} else if (opline->extended_value == 0 &&
call_stack[call].opline &&
call_stack[call].opline->opcode == ZEND_INIT_FCALL_BY_NAME &&
- ZEND_OP2_TYPE(call_stack[call].opline) == IS_CONST) {
+ ZEND_OP2_IS_CONST_STRING(call_stack[call].opline)) {
zend_op *fcall = call_stack[call].opline;
diff --git a/ext/opcache/Optimizer/pass1_5.c b/ext/opcache/Optimizer/pass1_5.c
index b2e5b1cb3c..5c6f8efed6 100644
--- a/ext/opcache/Optimizer/pass1_5.c
+++ b/ext/opcache/Optimizer/pass1_5.c
@@ -463,7 +463,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
zval t;
ZVAL_LONG(&t, Z_STRLEN(ZEND_OP1_LITERAL(opline)));
- replace_tmp_by_const(op_array, opline + 1, ZEND_RESULT(opline).var, &t TSRMLS_CC);
+ replace_var_by_const(op_array, opline + 1, ZEND_RESULT(opline).var, &t TSRMLS_CC);
literal_dtor(&ZEND_OP1_LITERAL(opline));
MAKE_NOP(opline);
}
@@ -476,7 +476,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
break;
}
ZVAL_TRUE(&c);
- replace_tmp_by_const(op_array, opline, tv, &c TSRMLS_CC);
+ replace_var_by_const(op_array, opline, tv, &c TSRMLS_CC);
literal_dtor(&ZEND_OP1_LITERAL(opline));
MAKE_NOP(opline);
}
diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c
index 3391694e24..7c59d01254 100644
--- a/ext/opcache/zend_accelerator_util_funcs.c
+++ b/ext/opcache/zend_accelerator_util_funcs.c
@@ -326,28 +326,44 @@ static inline void zend_clone_zval(zval *src, int bind TSRMLS_DC)
#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
static zend_ast *zend_ast_clone(zend_ast *ast TSRMLS_DC)
{
- int i;
- zend_ast *node;
-
- if (ast->kind == ZEND_CONST) {
- node = emalloc(sizeof(zend_ast) + sizeof(zval));
- node->kind = ZEND_CONST;
- node->children = 0;
- ZVAL_COPY_VALUE(&node->u.val, &ast->u.val);
- zend_clone_zval(&node->u.val, 0 TSRMLS_CC);
+ zend_uint i;
+
+ if (ast->kind == ZEND_AST_ZVAL) {
+ zend_ast_zval *copy = emalloc(sizeof(zend_ast_zval));
+ copy->kind = ZEND_AST_ZVAL;
+ copy->attr = ast->attr;
+ ZVAL_COPY_VALUE(&copy->val, zend_ast_get_zval(ast));
+ zend_clone_zval(&copy->val, 0 TSRMLS_CC);
+ return (zend_ast *) copy;
+ } else if (zend_ast_is_list(ast)) {
+ zend_ast_list *list = zend_ast_get_list(ast);
+ zend_ast_list *copy = emalloc(
+ sizeof(zend_ast_list) + sizeof(zend_ast *) * (list->children - 1));
+ copy->kind = list->kind;
+ copy->attr = list->attr;
+ copy->children = list->children;
+ for (i = 0; i < list->children; i++) {
+ if (list->child[i]) {
+ copy->child[i] = zend_ast_clone(list->child[i] TSRMLS_CC);
+ } else {
+ copy->child[i] = NULL;
+ }
+ }
+ return (zend_ast *) copy;
} else {
- node = emalloc(sizeof(zend_ast) + sizeof(zend_ast*) * (ast->children - 1));
- node->kind = ast->kind;
- node->children = ast->children;
- for (i = 0; i < ast->children; i++) {
- if ((&ast->u.child)[i]) {
- (&node->u.child)[i] = zend_ast_clone((&ast->u.child)[i] TSRMLS_CC);
+ zend_uint children = zend_ast_get_num_children(ast);
+ zend_ast *copy = emalloc(sizeof(zend_ast) + sizeof(zend_ast *) * (children - 1));
+ copy->kind = ast->kind;
+ copy->attr = ast->attr;
+ for (i = 0; i < children; i++) {
+ if (ast->child[i]) {
+ copy->child[i] = zend_ast_clone(ast->child[i] TSRMLS_CC);
} else {
- (&node->u.child)[i] = NULL;
+ copy->child[i] = NULL;
}
}
+ return copy;
}
- return node;
}
#endif
diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c
index 070d77670b..d703235a5c 100644
--- a/ext/opcache/zend_persist.c
+++ b/ext/opcache/zend_persist.c
@@ -152,20 +152,33 @@ static void zend_hash_persist_immutable(HashTable *ht TSRMLS_DC)
#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
static zend_ast *zend_persist_ast(zend_ast *ast TSRMLS_DC)
{
- int i;
+ zend_uint i;
zend_ast *node;
- if (ast->kind == ZEND_CONST) {
- node = zend_accel_memdup(ast, sizeof(zend_ast));
- zend_persist_zval(&node->u.val TSRMLS_CC);
+ if (ast->kind == ZEND_AST_ZVAL) {
+ zend_ast_zval *copy = zend_accel_memdup(ast, sizeof(zend_ast_zval));
+ zend_persist_zval(&copy->val TSRMLS_CC);
+ node = (zend_ast *) copy;
+ } else if (zend_ast_is_list(ast)) {
+ zend_ast_list *list = zend_ast_get_list(ast);
+ zend_ast_list *copy = zend_accel_memdup(ast,
+ sizeof(zend_ast_list) + sizeof(zend_ast *) * (list->children - 1));
+ for (i = 0; i < list->children; i++) {
+ if (copy->child[i]) {
+ copy->child[i] = zend_persist_ast(copy->child[i] TSRMLS_CC);
+ }
+ }
+ node = (zend_ast *) copy;
} else {
- node = zend_accel_memdup(ast, sizeof(zend_ast) + sizeof(zend_ast*) * (ast->children - 1));
- for (i = 0; i < ast->children; i++) {
- if ((&node->u.child)[i]) {
- (&node->u.child)[i] = zend_persist_ast((&node->u.child)[i] TSRMLS_CC);
+ zend_uint children = zend_ast_get_num_children(ast);
+ node = zend_accel_memdup(ast, sizeof(zend_ast) + sizeof(zend_ast *) * (children - 1));
+ for (i = 0; i < children; i++) {
+ if (node->child[i]) {
+ node->child[i] = zend_persist_ast(node->child[i] TSRMLS_CC);
}
}
}
+
efree(ast);
return node;
}
diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c
index 0732cc2188..f26a6fe195 100644
--- a/ext/opcache/zend_persist_calc.c
+++ b/ext/opcache/zend_persist_calc.c
@@ -88,17 +88,26 @@ static uint zend_hash_persist_calc(HashTable *ht, uint (*pPersistElement)(zval *
#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
static uint zend_persist_ast_calc(zend_ast *ast TSRMLS_DC)
{
- int i;
+ zend_uint i;
START_SIZE();
- if (ast->kind == ZEND_CONST) {
- ADD_SIZE(sizeof(zend_ast));
- ADD_SIZE(zend_persist_zval_calc(&ast->u.val TSRMLS_CC));
+ if (ast->kind == ZEND_AST_ZVAL) {
+ ADD_SIZE(sizeof(zend_ast_zval));
+ ADD_SIZE(zend_persist_zval_calc(zend_ast_get_zval(ast) TSRMLS_CC));
+ } else if (zend_ast_is_list(ast)) {
+ zend_ast_list *list = zend_ast_get_list(ast);
+ ADD_SIZE(sizeof(zend_ast_list) + sizeof(zend_ast *) * (list->children - 1));
+ for (i = 0; i < list->children; i++) {
+ if (list->child[i]) {
+ ADD_SIZE(zend_persist_ast_calc(list->child[i] TSRMLS_CC));
+ }
+ }
} else {
- ADD_SIZE(sizeof(zend_ast) + sizeof(zend_ast*) * (ast->children - 1));
- for (i = 0; i < ast->children; i++) {
- if ((&ast->u.child)[i]) {
- ADD_SIZE(zend_persist_ast_calc((&ast->u.child)[i] TSRMLS_CC));
+ zend_uint children = zend_ast_get_num_children(ast);
+ ADD_SIZE(sizeof(zend_ast) + sizeof(zend_ast *) * (children - 1));
+ for (i = 0; i < children; i++) {
+ if (ast->child[i]) {
+ ADD_SIZE(zend_persist_ast_calc(ast->child[i] TSRMLS_CC));
}
}
}