cvs: ZendEngine2 / zend_compile.c zend_compile.h zend_language_parser.y zend_vm_def.h zend_vm_execute.h zend_vm_opcodes.h
| From: | Dmitry Stogov | Date: | Mon, 07 Feb 2005 16:09:57 +0000 |
| Subject: | cvs: ZendEngine2 / zend_compile.c zend_compile.h zend_language_parser.y zend_vm_def.h zend_vm_execute.h zend_vm_opcodes.h | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-3375@lists.php.net to get a copy of this message | ||
dmitry Mon Feb 7 11:09:57 2005 EDT
Modified files:
/ZendEngine2 zend_compile.c zend_compile.h zend_language_parser.y
zend_vm_def.h zend_vm_execute.h zend_vm_opcodes.h
Log:
foreash($a as $key => $val) optimization
Removed temorary array creation on each iteration.
http://cvs.php.net/diff.php/ZendEngine2/zend_compile.c?r1=1.607&r2=1.608&ty=u Index: ZendEngine2/zend_compile.c diff -u ZendEngine2/zend_compile.c:1.607 ZendEngine2/zend_compile.c:1.608 --- ZendEngine2/zend_compile.c:1.607 Mon Feb 7 10:22:37 2005 +++ ZendEngine2/zend_compile.c Mon Feb 7 11:09:54 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.c,v 1.607 2005/02/07 15:22:37 helly Exp $ */ +/* $Id: zend_compile.c,v 1.608 2005/02/07 16:09:54 dmitry Exp $ */ #include <zend_language_parser.h> #include "zend.h" @@ -3343,7 +3343,7 @@ } -void zend_do_foreach_begin(znode *foreach_token, znode *array, znode *open_brackets_token, znode *as_token, int variable TSRMLS_DC) +void zend_do_foreach_begin(znode *foreach_token, znode *array, znode *open_brackets_token, int variable TSRMLS_DC) { zend_op *opline; zend_bool is_variable; @@ -3398,21 +3398,27 @@ opline = get_next_op(CG(active_op_array) TSRMLS_CC); opline->opcode = ZEND_FE_FETCH; - opline->result.op_type = IS_TMP_VAR; + opline->result.op_type = IS_VAR; opline->result.u.var = get_temporary_variable(CG(active_op_array)); opline->op1 = *open_brackets_token; opline->extended_value = 0; SET_UNUSED(opline->op2); - *as_token = opline->result; + + opline = get_next_op(CG(active_op_array) TSRMLS_CC); + opline->opcode = ZEND_OP_DATA; + opline->op1.op_type = IS_UNUSED; + opline->op2.op_type = IS_UNUSED; + opline->result.op_type = IS_UNUSED; } -void zend_do_foreach_cont(znode *value, znode *key, znode *as_token, znode *foreach_token TSRMLS_DC) +void zend_do_foreach_cont(znode *value, znode *key, znode *foreach_token TSRMLS_DC) { zend_op *opline; - znode result_value, result_key, dummy; + znode dummy; zend_bool assign_by_ref=0; + opline = &CG(active_op_array)->opcodes[foreach_token->u.opline_num]; if (key->op_type != IS_UNUSED) { znode *tmp; @@ -3422,66 +3428,38 @@ value = tmp; /* Mark extended_value in case both key and value are being used */ - CG(active_op_array)->opcodes[foreach_token->u.opline_num].extended_value |= ZEND_FE_FETCH_WITH_KEY; + opline->extended_value |= ZEND_FE_FETCH_WITH_KEY; } if ((key->op_type != IS_UNUSED) && (key->u.EA.type & ZEND_PARSED_REFERENCE_VARIABLE)) { zend_error(E_COMPILE_ERROR, "Key element cannot be a reference"); } - + if (value->u.EA.type & ZEND_PARSED_REFERENCE_VARIABLE) { assign_by_ref = 1; - if (!CG(active_op_array)->opcodes[foreach_token->u.opline_num-1].extended_value) { + if (!(opline-1)->extended_value) { zend_error(E_COMPILE_ERROR, "Cannot create references to elements of a temporary array expression"); } /* Mark extended_value for assign-by-reference */ - CG(active_op_array)->opcodes[foreach_token->u.opline_num].extended_value |= ZEND_FE_FETCH_BYREF; - } - - if (key->op_type != IS_UNUSED) { - opline = get_next_op(CG(active_op_array) TSRMLS_CC); - opline->opcode = ZEND_FETCH_DIM_TMP_VAR; - opline->result.op_type = IS_VAR; - opline->result.u.EA.type = 0; - opline->result.u.opline_num = get_temporary_variable(CG(active_op_array)); - opline->op1 = *as_token; - opline->op2.op_type = IS_CONST; - opline->op2.u.constant.type = IS_LONG; - opline->op2.u.constant.value.lval = 0; - opline->extended_value = ZEND_FETCH_STANDARD; /* ignored in fetch_dim_tmp_var, but what the hell. */ - result_value = opline->result; - - opline = get_next_op(CG(active_op_array) TSRMLS_CC); - opline->opcode = ZEND_FETCH_DIM_TMP_VAR; - opline->result.op_type = IS_VAR; - opline->result.u.EA.type = 0; - opline->result.u.opline_num = get_temporary_variable(CG(active_op_array)); - opline->op1 = *as_token; - opline->op2.op_type = IS_CONST; - opline->op2.u.constant.type = IS_LONG; - opline->op2.u.constant.value.lval = 1; - opline->extended_value = ZEND_FETCH_STANDARD; /* ignored in fetch_dim_tmp_var, but what the hell. */ - result_key = opline->result; - } else { - result_value = CG(active_op_array)->opcodes[foreach_token->u.opline_num].result; + opline->extended_value |= ZEND_FE_FETCH_BYREF; } if (assign_by_ref) { - if (key->op_type == IS_UNUSED) { - /* Mark FE_FETCH as IS_VAR as it holds the data directly as a value */ - CG(active_op_array)->opcodes[foreach_token->u.opline_num].result.op_type = IS_VAR; - zend_do_assign_ref(NULL, value, &CG(active_op_array)->opcodes[foreach_token->u.opline_num].result TSRMLS_CC); - } else { - zend_do_assign_ref(NULL, value, &result_value TSRMLS_CC); - } + /* Mark FE_FETCH as IS_VAR as it holds the data directly as a value */ + zend_do_assign_ref(NULL, value, &opline->result TSRMLS_CC); } else { - zend_do_assign(&dummy, value, &result_value TSRMLS_CC); + zend_do_assign(&dummy, value, &opline->result TSRMLS_CC); + zend_do_free(&dummy TSRMLS_CC); } - CG(active_op_array)->opcodes[CG(active_op_array)->last-1].result.u.EA.type |= EXT_TYPE_UNUSED; + if (key->op_type != IS_UNUSED) { - zend_do_assign(&dummy, key, &result_key TSRMLS_CC); - CG(active_op_array)->opcodes[CG(active_op_array)->last-1].result.u.EA.type |= EXT_TYPE_UNUSED; - zend_do_free(as_token TSRMLS_CC); + ++opline; + opline->result.op_type = IS_TMP_VAR; + opline->result.u.EA.type = 0; + opline->result.u.opline_num = get_temporary_variable(CG(active_op_array)); + + zend_do_assign(&dummy, key, &opline->result TSRMLS_CC); + zend_do_free(&dummy TSRMLS_CC); } do_begin_loop(TSRMLS_C); @@ -3489,7 +3467,7 @@ } -void zend_do_foreach_end(znode *foreach_token, znode *open_brackets_token TSRMLS_DC) +void zend_do_foreach_end(znode *foreach_token TSRMLS_DC) { zend_op *container_ptr; zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC); http://cvs.php.net/diff.php/ZendEngine2/zend_compile.h?r1=1.300&r2=1.301&ty=u Index: ZendEngine2/zend_compile.h diff -u ZendEngine2/zend_compile.h:1.300 ZendEngine2/zend_compile.h:1.301 --- ZendEngine2/zend_compile.h:1.300 Mon Feb 7 10:22:38 2005 +++ ZendEngine2/zend_compile.h Mon Feb 7 11:09:54 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.h,v 1.300 2005/02/07 15:22:38 helly Exp $ */ +/* $Id: zend_compile.h,v 1.301 2005/02/07 16:09:54 dmitry Exp $ */ #ifndef ZEND_COMPILE_H #define ZEND_COMPILE_H @@ -461,9 +461,9 @@ void zend_do_instanceof(znode *result, znode *expr, znode *class_znode, int type TSRMLS_DC); -void zend_do_foreach_begin(znode *foreach_token, znode *array, znode *open_brackets_token, znode *as_token, int variable TSRMLS_DC); -void zend_do_foreach_cont(znode *value, znode *key, znode *as_token, znode *foreach_token TSRMLS_DC); -void zend_do_foreach_end(znode *foreach_token, znode *open_brackets_token TSRMLS_DC); +void zend_do_foreach_begin(znode *foreach_token, znode *array, znode *open_brackets_token, int variable TSRMLS_DC); +void zend_do_foreach_cont(znode *value, znode *key, znode *foreach_token TSRMLS_DC); +void zend_do_foreach_end(znode *foreach_token TSRMLS_DC); void zend_do_declare_begin(TSRMLS_D); void zend_do_declare_stmt(znode *var, znode *val TSRMLS_DC); http://cvs.php.net/diff.php/ZendEngine2/zend_language_parser.y?r1=1.153&r2=1.154&ty=u Index: ZendEngine2/zend_language_parser.y diff -u ZendEngine2/zend_language_parser.y:1.153 ZendEngine2/zend_language_parser.y:1.154 --- ZendEngine2/zend_language_parser.y:1.153 Mon Feb 7 10:22:38 2005 +++ ZendEngine2/zend_language_parser.y Mon Feb 7 11:09:54 2005 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_language_parser.y,v 1.153 2005/02/07 15:22:38 helly Exp $ */ +/* $Id: zend_language_parser.y,v 1.154 2005/02/07 16:09:54 dmitry Exp $ */ /* * LALR shift/reduce conflicts and how they are resolved: @@ -209,8 +209,8 @@ | expr ';' { zend_do_free(&$1 TSRMLS_CC); } | T_USE use_filename ';' { zend_error(E_COMPILE_ERROR,"use: Not yet supported. Please use include_once() or require_once()"); zval_dtor(&$2.u.constant); } | T_UNSET '(' unset_variables ')' ';' - | T_FOREACH '(' variable T_AS { zend_do_foreach_begin(&$1, &$3, &$2, &$4, 1 TSRMLS_CC); } foreach_variable foreach_optional_arg ')' { zend_do_foreach_cont(&$6, &$7, &$4, &$1 TSRMLS_CC); } foreach_statement { zend_do_foreach_end(&$1, &$2 TSRMLS_CC); } - | T_FOREACH '(' expr_without_variable T_AS { zend_do_foreach_begin(&$1, &$3, &$2, &$4, 0 TSRMLS_CC); } w_variable foreach_optional_arg ')' { zend_do_foreach_cont(&$6, &$7, &$4, &$1 TSRMLS_CC); } foreach_statement { zend_do_foreach_end(&$1, &$2 TSRMLS_CC); } + | T_FOREACH '(' variable T_AS { zend_do_foreach_begin(&$1, &$3, &$2, 1 TSRMLS_CC); } foreach_variable foreach_optional_arg ')' { zend_do_foreach_cont(&$6, &$7, &$1 TSRMLS_CC); } foreach_statement { zend_do_foreach_end(&$1 TSRMLS_CC); } + | T_FOREACH '(' expr_without_variable T_AS { zend_do_foreach_begin(&$1, &$3, &$2, 0 TSRMLS_CC); } w_variable foreach_optional_arg ')' { zend_do_foreach_cont(&$6, &$7, &$1 TSRMLS_CC); } foreach_statement { zend_do_foreach_end(&$1 TSRMLS_CC); } | T_DECLARE { $1.u.opline_num = get_next_op_number(CG(active_op_array)); zend_do_declare_begin(TSRMLS_C); } '(' declare_list ')' declare_statement { zend_do_declare_end(&$1 TSRMLS_CC); } | ';' /* empty statement */ | T_TRY { zend_do_try(&$1 TSRMLS_CC); } '{' inner_statement_list '}' http://cvs.php.net/diff.php/ZendEngine2/zend_vm_def.h?r1=1.13&r2=1.14&ty=u Index: ZendEngine2/zend_vm_def.h diff -u ZendEngine2/zend_vm_def.h:1.13 ZendEngine2/zend_vm_def.h:1.14 --- ZendEngine2/zend_vm_def.h:1.13 Sat Feb 5 09:01:58 2005 +++ ZendEngine2/zend_vm_def.h Mon Feb 7 11:09:54 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_def.h,v 1.13 2005/02/05 14:01:58 helly Exp $ */ +/* $Id: zend_vm_def.h,v 1.14 2005/02/07 16:09:54 dmitry Exp $ */ ZEND_VM_HANDLER(1, ZEND_ADD, CONST|TMP|VAR|CV, CONST|TMP|VAR|CV) { @@ -2930,7 +2930,7 @@ zend_op *opline = EX(opline); zend_free_op free_op1; zval *array = GET_OP1_ZVAL_PTR(BP_VAR_R); - zval **value, *key; + zval **value; char *str_key; uint str_key_len; ulong int_key; @@ -3018,29 +3018,17 @@ if (opline->extended_value & ZEND_FE_FETCH_BYREF) { SEPARATE_ZVAL_IF_NOT_REF(value); (*value)->is_ref = 1; - } - - if (!use_key) { - if (opline->extended_value & ZEND_FE_FETCH_BYREF) { - EX_T(opline->result.u.var).var.ptr_ptr = value; - (*value)->refcount++; - } else { - zval *result = &EX_T(opline->result.u.var).tmp_var; - - *result = **value; - zval_copy_ctor(result); - } - } else { - zval *result = &EX_T(opline->result.u.var).tmp_var; - + EX_T(opline->result.u.var).var.ptr_ptr = value; (*value)->refcount++; + } else { + EX_T(opline->result.u.var).var.ptr_ptr = value; + PZVAL_LOCK(*EX_T(opline->result.u.var).var.ptr_ptr); + AI_USE_PTR(EX_T(opline->result.u.var).var); + } - array_init(result); - - zend_hash_index_update(result->value.ht, 0, value, sizeof(zval *), NULL); - - ALLOC_ZVAL(key); - INIT_PZVAL(key); + if (use_key) { + zend_op *op_data = opline+1; + zval *key = &EX_T(op_data->result.u.var).tmp_var; switch (key_type) { case HASH_KEY_IS_STRING: @@ -3054,9 +3042,9 @@ break; EMPTY_SWITCH_DEFAULT_CASE() } - zend_hash_index_update(result->value.ht, 1, &key, sizeof(zval *), NULL); } + ZEND_VM_INC_OPCODE(); ZEND_VM_NEXT_OPCODE(); } http://cvs.php.net/diff.php/ZendEngine2/zend_vm_execute.h?r1=1.15&r2=1.16&ty=u Index: ZendEngine2/zend_vm_execute.h diff -u ZendEngine2/zend_vm_execute.h:1.15 ZendEngine2/zend_vm_execute.h:1.16 --- ZendEngine2/zend_vm_execute.h:1.15 Sat Feb 5 09:01:58 2005 +++ ZendEngine2/zend_vm_execute.h Mon Feb 7 11:09:54 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_execute.h,v 1.15 2005/02/05 14:01:58 helly Exp $ */ +/* $Id: zend_vm_execute.h,v 1.16 2005/02/07 16:09:54 dmitry Exp $ */ #define ZEND_VM_CONTINUE() return 0 @@ -7550,7 +7550,7 @@ zend_op *opline = EX(opline); zend_free_op free_op1; zval *array = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); - zval **value, *key; + zval **value; char *str_key; uint str_key_len; ulong int_key; @@ -7638,29 +7638,17 @@ if (opline->extended_value & ZEND_FE_FETCH_BYREF) { SEPARATE_ZVAL_IF_NOT_REF(value); (*value)->is_ref = 1; - } - - if (!use_key) { - if (opline->extended_value & ZEND_FE_FETCH_BYREF) { - EX_T(opline->result.u.var).var.ptr_ptr = value; - (*value)->refcount++; - } else { - zval *result = &EX_T(opline->result.u.var).tmp_var; - - *result = **value; - zval_copy_ctor(result); - } - } else { - zval *result = &EX_T(opline->result.u.var).tmp_var; - + EX_T(opline->result.u.var).var.ptr_ptr = value; (*value)->refcount++; + } else { + EX_T(opline->result.u.var).var.ptr_ptr = value; + PZVAL_LOCK(*EX_T(opline->result.u.var).var.ptr_ptr); + AI_USE_PTR(EX_T(opline->result.u.var).var); + } - array_init(result); - - zend_hash_index_update(result->value.ht, 0, value, sizeof(zval *), NULL); - - ALLOC_ZVAL(key); - INIT_PZVAL(key); + if (use_key) { + zend_op *op_data = opline+1; + zval *key = &EX_T(op_data->result.u.var).tmp_var; switch (key_type) { case HASH_KEY_IS_STRING: @@ -7674,9 +7662,9 @@ break; EMPTY_SWITCH_DEFAULT_CASE() } - zend_hash_index_update(result->value.ht, 1, &key, sizeof(zval *), NULL); } + ZEND_VM_INC_OPCODE(); ZEND_VM_NEXT_OPCODE(); } @@ -30655,7 +30643,7 @@ zend_op *opline = EX(opline); zend_free_op free_op1; zval *array = get_zval_ptr(&opline->op1, EX(Ts), &free_op1, BP_VAR_R); - zval **value, *key; + zval **value; char *str_key; uint str_key_len; ulong int_key; @@ -30743,29 +30731,17 @@ if (opline->extended_value & ZEND_FE_FETCH_BYREF) { SEPARATE_ZVAL_IF_NOT_REF(value); (*value)->is_ref = 1; - } - - if (!use_key) { - if (opline->extended_value & ZEND_FE_FETCH_BYREF) { - EX_T(opline->result.u.var).var.ptr_ptr = value; - (*value)->refcount++; - } else { - zval *result = &EX_T(opline->result.u.var).tmp_var; - - *result = **value; - zval_copy_ctor(result); - } - } else { - zval *result = &EX_T(opline->result.u.var).tmp_var; - + EX_T(opline->result.u.var).var.ptr_ptr = value; (*value)->refcount++; + } else { + EX_T(opline->result.u.var).var.ptr_ptr = value; + PZVAL_LOCK(*EX_T(opline->result.u.var).var.ptr_ptr); + AI_USE_PTR(EX_T(opline->result.u.var).var); + } - array_init(result); - - zend_hash_index_update(result->value.ht, 0, value, sizeof(zval *), NULL); - - ALLOC_ZVAL(key); - INIT_PZVAL(key); + if (use_key) { + zend_op *op_data = opline+1; + zval *key = &EX_T(op_data->result.u.var).tmp_var; switch (key_type) { case HASH_KEY_IS_STRING: @@ -30779,9 +30755,9 @@ break; EMPTY_SWITCH_DEFAULT_CASE() } - zend_hash_index_update(result->value.ht, 1, &key, sizeof(zval *), NULL); } + ZEND_VM_INC_OPCODE(); ZEND_VM_NEXT_OPCODE(); } http://cvs.php.net/diff.php/ZendEngine2/zend_vm_opcodes.h?r1=1.5&r2=1.6&ty=u Index: ZendEngine2/zend_vm_opcodes.h diff -u ZendEngine2/zend_vm_opcodes.h:1.5 ZendEngine2/zend_vm_opcodes.h:1.6 --- ZendEngine2/zend_vm_opcodes.h:1.5 Sat Feb 5 09:01:59 2005 +++ ZendEngine2/zend_vm_opcodes.h Mon Feb 7 11:09:54 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_opcodes.h,v 1.5 2005/02/05 14:01:59 helly Exp $ */ +/* $Id: zend_vm_opcodes.h,v 1.6 2005/02/07 16:09:54 dmitry Exp $ */ #define ZEND_NOP 0 #define ZEND_ADD 1
http://cvs.php.net/diff.php/ZendEngine2/zend_compile.c?r1=1.607&r2=1.608&ty=u Index: ZendEngine2/zend_compile.c diff -u ZendEngine2/zend_compile.c:1.607 ZendEngine2/zend_compile.c:1.608 --- ZendEngine2/zend_compile.c:1.607 Mon Feb 7 10:22:37 2005 +++ ZendEngine2/zend_compile.c Mon Feb 7 11:09:54 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.c,v 1.607 2005/02/07 15:22:37 helly Exp $ */ +/* $Id: zend_compile.c,v 1.608 2005/02/07 16:09:54 dmitry Exp $ */ #include <zend_language_parser.h> #include "zend.h" @@ -3343,7 +3343,7 @@ } -void zend_do_foreach_begin(znode *foreach_token, znode *array, znode *open_brackets_token, znode *as_token, int variable TSRMLS_DC) +void zend_do_foreach_begin(znode *foreach_token, znode *array, znode *open_brackets_token, int variable TSRMLS_DC) { zend_op *opline; zend_bool is_variable; @@ -3398,21 +3398,27 @@ opline = get_next_op(CG(active_op_array) TSRMLS_CC); opline->opcode = ZEND_FE_FETCH; - opline->result.op_type = IS_TMP_VAR; + opline->result.op_type = IS_VAR; opline->result.u.var = get_temporary_variable(CG(active_op_array)); opline->op1 = *open_brackets_token; opline->extended_value = 0; SET_UNUSED(opline->op2); - *as_token = opline->result; + + opline = get_next_op(CG(active_op_array) TSRMLS_CC); + opline->opcode = ZEND_OP_DATA; + opline->op1.op_type = IS_UNUSED; + opline->op2.op_type = IS_UNUSED; + opline->result.op_type = IS_UNUSED; } -void zend_do_foreach_cont(znode *value, znode *key, znode *as_token, znode *foreach_token TSRMLS_DC) +void zend_do_foreach_cont(znode *value, znode *key, znode *foreach_token TSRMLS_DC) { zend_op *opline; - znode result_value, result_key, dummy; + znode dummy; zend_bool assign_by_ref=0; + opline = &CG(active_op_array)->opcodes[foreach_token->u.opline_num]; if (key->op_type != IS_UNUSED) { znode *tmp; @@ -3422,66 +3428,38 @@ value = tmp; /* Mark extended_value in case both key and value are being used */ - CG(active_op_array)->opcodes[foreach_token->u.opline_num].extended_value |= ZEND_FE_FETCH_WITH_KEY; + opline->extended_value |= ZEND_FE_FETCH_WITH_KEY; } if ((key->op_type != IS_UNUSED) && (key->u.EA.type & ZEND_PARSED_REFERENCE_VARIABLE)) { zend_error(E_COMPILE_ERROR, "Key element cannot be a reference"); } - + if (value->u.EA.type & ZEND_PARSED_REFERENCE_VARIABLE) { assign_by_ref = 1; - if (!CG(active_op_array)->opcodes[foreach_token->u.opline_num-1].extended_value) { + if (!(opline-1)->extended_value) { zend_error(E_COMPILE_ERROR, "Cannot create references to elements of a temporary array expression"); } /* Mark extended_value for assign-by-reference */ - CG(active_op_array)->opcodes[foreach_token->u.opline_num].extended_value |= ZEND_FE_FETCH_BYREF; - } - - if (key->op_type != IS_UNUSED) { - opline = get_next_op(CG(active_op_array) TSRMLS_CC); - opline->opcode = ZEND_FETCH_DIM_TMP_VAR; - opline->result.op_type = IS_VAR; - opline->result.u.EA.type = 0; - opline->result.u.opline_num = get_temporary_variable(CG(active_op_array)); - opline->op1 = *as_token; - opline->op2.op_type = IS_CONST; - opline->op2.u.constant.type = IS_LONG; - opline->op2.u.constant.value.lval = 0; - opline->extended_value = ZEND_FETCH_STANDARD; /* ignored in fetch_dim_tmp_var, but what the hell. */ - result_value = opline->result; - - opline = get_next_op(CG(active_op_array) TSRMLS_CC); - opline->opcode = ZEND_FETCH_DIM_TMP_VAR; - opline->result.op_type = IS_VAR; - opline->result.u.EA.type = 0; - opline->result.u.opline_num = get_temporary_variable(CG(active_op_array)); - opline->op1 = *as_token; - opline->op2.op_type = IS_CONST; - opline->op2.u.constant.type = IS_LONG; - opline->op2.u.constant.value.lval = 1; - opline->extended_value = ZEND_FETCH_STANDARD; /* ignored in fetch_dim_tmp_var, but what the hell. */ - result_key = opline->result; - } else { - result_value = CG(active_op_array)->opcodes[foreach_token->u.opline_num].result; + opline->extended_value |= ZEND_FE_FETCH_BYREF; } if (assign_by_ref) { - if (key->op_type == IS_UNUSED) { - /* Mark FE_FETCH as IS_VAR as it holds the data directly as a value */ - CG(active_op_array)->opcodes[foreach_token->u.opline_num].result.op_type = IS_VAR; - zend_do_assign_ref(NULL, value, &CG(active_op_array)->opcodes[foreach_token->u.opline_num].result TSRMLS_CC); - } else { - zend_do_assign_ref(NULL, value, &result_value TSRMLS_CC); - } + /* Mark FE_FETCH as IS_VAR as it holds the data directly as a value */ + zend_do_assign_ref(NULL, value, &opline->result TSRMLS_CC); } else { - zend_do_assign(&dummy, value, &result_value TSRMLS_CC); + zend_do_assign(&dummy, value, &opline->result TSRMLS_CC); + zend_do_free(&dummy TSRMLS_CC); } - CG(active_op_array)->opcodes[CG(active_op_array)->last-1].result.u.EA.type |= EXT_TYPE_UNUSED; + if (key->op_type != IS_UNUSED) { - zend_do_assign(&dummy, key, &result_key TSRMLS_CC); - CG(active_op_array)->opcodes[CG(active_op_array)->last-1].result.u.EA.type |= EXT_TYPE_UNUSED; - zend_do_free(as_token TSRMLS_CC); + ++opline; + opline->result.op_type = IS_TMP_VAR; + opline->result.u.EA.type = 0; + opline->result.u.opline_num = get_temporary_variable(CG(active_op_array)); + + zend_do_assign(&dummy, key, &opline->result TSRMLS_CC); + zend_do_free(&dummy TSRMLS_CC); } do_begin_loop(TSRMLS_C); @@ -3489,7 +3467,7 @@ } -void zend_do_foreach_end(znode *foreach_token, znode *open_brackets_token TSRMLS_DC) +void zend_do_foreach_end(znode *foreach_token TSRMLS_DC) { zend_op *container_ptr; zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC); http://cvs.php.net/diff.php/ZendEngine2/zend_compile.h?r1=1.300&r2=1.301&ty=u Index: ZendEngine2/zend_compile.h diff -u ZendEngine2/zend_compile.h:1.300 ZendEngine2/zend_compile.h:1.301 --- ZendEngine2/zend_compile.h:1.300 Mon Feb 7 10:22:38 2005 +++ ZendEngine2/zend_compile.h Mon Feb 7 11:09:54 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.h,v 1.300 2005/02/07 15:22:38 helly Exp $ */ +/* $Id: zend_compile.h,v 1.301 2005/02/07 16:09:54 dmitry Exp $ */ #ifndef ZEND_COMPILE_H #define ZEND_COMPILE_H @@ -461,9 +461,9 @@ void zend_do_instanceof(znode *result, znode *expr, znode *class_znode, int type TSRMLS_DC); -void zend_do_foreach_begin(znode *foreach_token, znode *array, znode *open_brackets_token, znode *as_token, int variable TSRMLS_DC); -void zend_do_foreach_cont(znode *value, znode *key, znode *as_token, znode *foreach_token TSRMLS_DC); -void zend_do_foreach_end(znode *foreach_token, znode *open_brackets_token TSRMLS_DC); +void zend_do_foreach_begin(znode *foreach_token, znode *array, znode *open_brackets_token, int variable TSRMLS_DC); +void zend_do_foreach_cont(znode *value, znode *key, znode *foreach_token TSRMLS_DC); +void zend_do_foreach_end(znode *foreach_token TSRMLS_DC); void zend_do_declare_begin(TSRMLS_D); void zend_do_declare_stmt(znode *var, znode *val TSRMLS_DC); http://cvs.php.net/diff.php/ZendEngine2/zend_language_parser.y?r1=1.153&r2=1.154&ty=u Index: ZendEngine2/zend_language_parser.y diff -u ZendEngine2/zend_language_parser.y:1.153 ZendEngine2/zend_language_parser.y:1.154 --- ZendEngine2/zend_language_parser.y:1.153 Mon Feb 7 10:22:38 2005 +++ ZendEngine2/zend_language_parser.y Mon Feb 7 11:09:54 2005 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_language_parser.y,v 1.153 2005/02/07 15:22:38 helly Exp $ */ +/* $Id: zend_language_parser.y,v 1.154 2005/02/07 16:09:54 dmitry Exp $ */ /* * LALR shift/reduce conflicts and how they are resolved: @@ -209,8 +209,8 @@ | expr ';' { zend_do_free(&$1 TSRMLS_CC); } | T_USE use_filename ';' { zend_error(E_COMPILE_ERROR,"use: Not yet supported. Please use include_once() or require_once()"); zval_dtor(&$2.u.constant); } | T_UNSET '(' unset_variables ')' ';' - | T_FOREACH '(' variable T_AS { zend_do_foreach_begin(&$1, &$3, &$2, &$4, 1 TSRMLS_CC); } foreach_variable foreach_optional_arg ')' { zend_do_foreach_cont(&$6, &$7, &$4, &$1 TSRMLS_CC); } foreach_statement { zend_do_foreach_end(&$1, &$2 TSRMLS_CC); } - | T_FOREACH '(' expr_without_variable T_AS { zend_do_foreach_begin(&$1, &$3, &$2, &$4, 0 TSRMLS_CC); } w_variable foreach_optional_arg ')' { zend_do_foreach_cont(&$6, &$7, &$4, &$1 TSRMLS_CC); } foreach_statement { zend_do_foreach_end(&$1, &$2 TSRMLS_CC); } + | T_FOREACH '(' variable T_AS { zend_do_foreach_begin(&$1, &$3, &$2, 1 TSRMLS_CC); } foreach_variable foreach_optional_arg ')' { zend_do_foreach_cont(&$6, &$7, &$1 TSRMLS_CC); } foreach_statement { zend_do_foreach_end(&$1 TSRMLS_CC); } + | T_FOREACH '(' expr_without_variable T_AS { zend_do_foreach_begin(&$1, &$3, &$2, 0 TSRMLS_CC); } w_variable foreach_optional_arg ')' { zend_do_foreach_cont(&$6, &$7, &$1 TSRMLS_CC); } foreach_statement { zend_do_foreach_end(&$1 TSRMLS_CC); } | T_DECLARE { $1.u.opline_num = get_next_op_number(CG(active_op_array)); zend_do_declare_begin(TSRMLS_C); } '(' declare_list ')' declare_statement { zend_do_declare_end(&$1 TSRMLS_CC); } | ';' /* empty statement */ | T_TRY { zend_do_try(&$1 TSRMLS_CC); } '{' inner_statement_list '}' http://cvs.php.net/diff.php/ZendEngine2/zend_vm_def.h?r1=1.13&r2=1.14&ty=u Index: ZendEngine2/zend_vm_def.h diff -u ZendEngine2/zend_vm_def.h:1.13 ZendEngine2/zend_vm_def.h:1.14 --- ZendEngine2/zend_vm_def.h:1.13 Sat Feb 5 09:01:58 2005 +++ ZendEngine2/zend_vm_def.h Mon Feb 7 11:09:54 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_def.h,v 1.13 2005/02/05 14:01:58 helly Exp $ */ +/* $Id: zend_vm_def.h,v 1.14 2005/02/07 16:09:54 dmitry Exp $ */ ZEND_VM_HANDLER(1, ZEND_ADD, CONST|TMP|VAR|CV, CONST|TMP|VAR|CV) { @@ -2930,7 +2930,7 @@ zend_op *opline = EX(opline); zend_free_op free_op1; zval *array = GET_OP1_ZVAL_PTR(BP_VAR_R); - zval **value, *key; + zval **value; char *str_key; uint str_key_len; ulong int_key; @@ -3018,29 +3018,17 @@ if (opline->extended_value & ZEND_FE_FETCH_BYREF) { SEPARATE_ZVAL_IF_NOT_REF(value); (*value)->is_ref = 1; - } - - if (!use_key) { - if (opline->extended_value & ZEND_FE_FETCH_BYREF) { - EX_T(opline->result.u.var).var.ptr_ptr = value; - (*value)->refcount++; - } else { - zval *result = &EX_T(opline->result.u.var).tmp_var; - - *result = **value; - zval_copy_ctor(result); - } - } else { - zval *result = &EX_T(opline->result.u.var).tmp_var; - + EX_T(opline->result.u.var).var.ptr_ptr = value; (*value)->refcount++; + } else { + EX_T(opline->result.u.var).var.ptr_ptr = value; + PZVAL_LOCK(*EX_T(opline->result.u.var).var.ptr_ptr); + AI_USE_PTR(EX_T(opline->result.u.var).var); + } - array_init(result); - - zend_hash_index_update(result->value.ht, 0, value, sizeof(zval *), NULL); - - ALLOC_ZVAL(key); - INIT_PZVAL(key); + if (use_key) { + zend_op *op_data = opline+1; + zval *key = &EX_T(op_data->result.u.var).tmp_var; switch (key_type) { case HASH_KEY_IS_STRING: @@ -3054,9 +3042,9 @@ break; EMPTY_SWITCH_DEFAULT_CASE() } - zend_hash_index_update(result->value.ht, 1, &key, sizeof(zval *), NULL); } + ZEND_VM_INC_OPCODE(); ZEND_VM_NEXT_OPCODE(); } http://cvs.php.net/diff.php/ZendEngine2/zend_vm_execute.h?r1=1.15&r2=1.16&ty=u Index: ZendEngine2/zend_vm_execute.h diff -u ZendEngine2/zend_vm_execute.h:1.15 ZendEngine2/zend_vm_execute.h:1.16 --- ZendEngine2/zend_vm_execute.h:1.15 Sat Feb 5 09:01:58 2005 +++ ZendEngine2/zend_vm_execute.h Mon Feb 7 11:09:54 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_execute.h,v 1.15 2005/02/05 14:01:58 helly Exp $ */ +/* $Id: zend_vm_execute.h,v 1.16 2005/02/07 16:09:54 dmitry Exp $ */ #define ZEND_VM_CONTINUE() return 0 @@ -7550,7 +7550,7 @@ zend_op *opline = EX(opline); zend_free_op free_op1; zval *array = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); - zval **value, *key; + zval **value; char *str_key; uint str_key_len; ulong int_key; @@ -7638,29 +7638,17 @@ if (opline->extended_value & ZEND_FE_FETCH_BYREF) { SEPARATE_ZVAL_IF_NOT_REF(value); (*value)->is_ref = 1; - } - - if (!use_key) { - if (opline->extended_value & ZEND_FE_FETCH_BYREF) { - EX_T(opline->result.u.var).var.ptr_ptr = value; - (*value)->refcount++; - } else { - zval *result = &EX_T(opline->result.u.var).tmp_var; - - *result = **value; - zval_copy_ctor(result); - } - } else { - zval *result = &EX_T(opline->result.u.var).tmp_var; - + EX_T(opline->result.u.var).var.ptr_ptr = value; (*value)->refcount++; + } else { + EX_T(opline->result.u.var).var.ptr_ptr = value; + PZVAL_LOCK(*EX_T(opline->result.u.var).var.ptr_ptr); + AI_USE_PTR(EX_T(opline->result.u.var).var); + } - array_init(result); - - zend_hash_index_update(result->value.ht, 0, value, sizeof(zval *), NULL); - - ALLOC_ZVAL(key); - INIT_PZVAL(key); + if (use_key) { + zend_op *op_data = opline+1; + zval *key = &EX_T(op_data->result.u.var).tmp_var; switch (key_type) { case HASH_KEY_IS_STRING: @@ -7674,9 +7662,9 @@ break; EMPTY_SWITCH_DEFAULT_CASE() } - zend_hash_index_update(result->value.ht, 1, &key, sizeof(zval *), NULL); } + ZEND_VM_INC_OPCODE(); ZEND_VM_NEXT_OPCODE(); } @@ -30655,7 +30643,7 @@ zend_op *opline = EX(opline); zend_free_op free_op1; zval *array = get_zval_ptr(&opline->op1, EX(Ts), &free_op1, BP_VAR_R); - zval **value, *key; + zval **value; char *str_key; uint str_key_len; ulong int_key; @@ -30743,29 +30731,17 @@ if (opline->extended_value & ZEND_FE_FETCH_BYREF) { SEPARATE_ZVAL_IF_NOT_REF(value); (*value)->is_ref = 1; - } - - if (!use_key) { - if (opline->extended_value & ZEND_FE_FETCH_BYREF) { - EX_T(opline->result.u.var).var.ptr_ptr = value; - (*value)->refcount++; - } else { - zval *result = &EX_T(opline->result.u.var).tmp_var; - - *result = **value; - zval_copy_ctor(result); - } - } else { - zval *result = &EX_T(opline->result.u.var).tmp_var; - + EX_T(opline->result.u.var).var.ptr_ptr = value; (*value)->refcount++; + } else { + EX_T(opline->result.u.var).var.ptr_ptr = value; + PZVAL_LOCK(*EX_T(opline->result.u.var).var.ptr_ptr); + AI_USE_PTR(EX_T(opline->result.u.var).var); + } - array_init(result); - - zend_hash_index_update(result->value.ht, 0, value, sizeof(zval *), NULL); - - ALLOC_ZVAL(key); - INIT_PZVAL(key); + if (use_key) { + zend_op *op_data = opline+1; + zval *key = &EX_T(op_data->result.u.var).tmp_var; switch (key_type) { case HASH_KEY_IS_STRING: @@ -30779,9 +30755,9 @@ break; EMPTY_SWITCH_DEFAULT_CASE() } - zend_hash_index_update(result->value.ht, 1, &key, sizeof(zval *), NULL); } + ZEND_VM_INC_OPCODE(); ZEND_VM_NEXT_OPCODE(); } http://cvs.php.net/diff.php/ZendEngine2/zend_vm_opcodes.h?r1=1.5&r2=1.6&ty=u Index: ZendEngine2/zend_vm_opcodes.h diff -u ZendEngine2/zend_vm_opcodes.h:1.5 ZendEngine2/zend_vm_opcodes.h:1.6 --- ZendEngine2/zend_vm_opcodes.h:1.5 Sat Feb 5 09:01:59 2005 +++ ZendEngine2/zend_vm_opcodes.h Mon Feb 7 11:09:54 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_opcodes.h,v 1.5 2005/02/05 14:01:59 helly Exp $ */ +/* $Id: zend_vm_opcodes.h,v 1.6 2005/02/07 16:09:54 dmitry Exp $ */ #define ZEND_NOP 0 #define ZEND_ADD 1