cvs: Zend(PHP_4_3) / zend_compile.c zend_compile.h zend_execute.c zend_language_parser.y php-src NEWS

From: Date: Fri, 24 Sep 2004 13:15:16 +0000
Subject: cvs: Zend(PHP_4_3) / zend_compile.c zend_compile.h zend_execute.c zend_language_parser.y php-src NEWS
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-3021@lists.php.net to get a copy of this message
derick Fri Sep 24 09:15:16 2004 EDT Modified files: (Branch: PHP_4_3) /php-src NEWS /Zend zend_compile.c zend_compile.h zend_execute.c zend_language_parser.y Log: - Backported Marcus' foreach() speedup patch from PHP 5.x.

http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1247.2.731&r2=1.1247.2.732&ty=u Index: php-src/NEWS diff -u php-src/NEWS:1.1247.2.731 php-src/NEWS:1.1247.2.732 --- php-src/NEWS:1.1247.2.731 Tue Sep 21 18:00:38 2004 +++ php-src/NEWS Fri Sep 24 09:15:12 2004 @@ -1,6 +1,7 @@ PHP 4 NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2004, Version 4.3.10 +- Backported Marcus' foreach() speedup patch from PHP 5.x. (Derick) - Fixed bug #29805 (HTTP Authentication Issues). (Uwe Schindler) 22 Sep 2004, Version 4.3.9 http://cvs.php.net/diff.php/Zend/zend_compile.c?r1=1.240.2.7&r2=1.240.2.8&ty=u Index: Zend/zend_compile.c diff -u Zend/zend_compile.c:1.240.2.7 Zend/zend_compile.c:1.240.2.8 --- Zend/zend_compile.c:1.240.2.7 Sun Aug 29 12:51:09 2004 +++ Zend/zend_compile.c Fri Sep 24 09:15:14 2004 @@ -2147,9 +2147,9 @@ } -void zend_do_foreach_cont(znode *value, znode *key, znode *as_token TSRMLS_DC) +void zend_do_foreach_cont(znode *value, znode *key, znode *as_token, znode *foreach_token TSRMLS_DC) { - zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC); + zend_op *opline; znode result_value, result_key, dummy; if (key->op_type != IS_UNUSED) { @@ -2159,18 +2159,10 @@ tmp = key; key = value; value = tmp; - } - 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; + /* 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; + } if (key->op_type != IS_UNUSED) { opline = get_next_op(CG(active_op_array) TSRMLS_CC); @@ -2181,9 +2173,23 @@ 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; } zend_do_assign(&dummy, value, &result_value TSRMLS_CC); @@ -2191,8 +2197,8 @@ 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); } - zend_do_free(as_token TSRMLS_CC); do_begin_loop(TSRMLS_C); INC_BPC(CG(active_op_array)); http://cvs.php.net/diff.php/Zend/zend_compile.h?r1=1.144.4.5&r2=1.144.4.6&ty=u Index: Zend/zend_compile.h diff -u Zend/zend_compile.h:1.144.4.5 Zend/zend_compile.h:1.144.4.6 --- Zend/zend_compile.h:1.144.4.5 Fri May 30 21:37:43 2003 +++ Zend/zend_compile.h Fri Sep 24 09:15:14 2004 @@ -326,7 +326,7 @@ void zend_do_isset_or_isempty(int type, znode *result, znode *variable 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 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_declare_begin(TSRMLS_D); @@ -576,6 +576,9 @@ #define ZEND_FETCH_STANDARD 0 #define ZEND_FETCH_ADD_LOCK 1 + +#define ZEND_FE_FETCH_BYREF 1 +#define ZEND_FE_FETCH_WITH_KEY 2 #define ZEND_MEMBER_FUNC_CALL 1<<0 #define ZEND_CTOR_CALL 1<<1 http://cvs.php.net/diff.php/Zend/zend_execute.c?r1=1.316.2.39&r2=1.316.2.40&ty=u Index: Zend/zend_execute.c diff -u Zend/zend_execute.c:1.316.2.39 Zend/zend_execute.c:1.316.2.40 --- Zend/zend_execute.c:1.316.2.39 Sun Aug 1 22:35:05 2004 +++ Zend/zend_execute.c Fri Sep 24 09:15:14 2004 @@ -2350,13 +2350,14 @@ } NEXT_OPCODE(); case ZEND_FE_FETCH: { - zval *array = get_zval_ptr(&EX(opline)->op1, EX(Ts), &EG(free_op1), BP_VAR_R); - zval *result = &EX(Ts)[EX(opline)->result.u.var].tmp_var; + zend_op *opline = EX(opline); + zval *array = get_zval_ptr(&opline->op1, EX(Ts), &EG(free_op1), BP_VAR_R); zval **value, *key; char *str_key; uint str_key_len; ulong int_key; HashTable *fe_ht; + zend_bool use_key = opline->extended_value & ZEND_FE_FETCH_WITH_KEY; PZVAL_LOCK(array); @@ -2370,27 +2371,33 @@ EX(opline) = op_array->opcodes+EX(opline)->op2.u.opline_num; continue; } - array_init(result); - - (*value)->refcount++; - zend_hash_index_update(result->value.ht, 0, value, sizeof(zval *), NULL); - - ALLOC_ZVAL(key); - INIT_PZVAL(key); - switch (zend_hash_get_current_key_ex(fe_ht, &str_key, &str_key_len, &int_key, 1, NULL)) { - case HASH_KEY_IS_STRING: - key->value.str.val = str_key; - key->value.str.len = str_key_len-1; - key->type = IS_STRING; - break; - case HASH_KEY_IS_LONG: - key->value.lval = int_key; - key->type = IS_LONG; - break; - EMPTY_SWITCH_DEFAULT_CASE() + zval *result = &EX(Ts)[opline->result.u.var].tmp_var; + if (!use_key) { + *result = **value; + zval_copy_ctor(result); + } else { + array_init(result); + + (*value)->refcount++; + zend_hash_index_update(result->value.ht, 0, value, sizeof(zval *), NULL); + + ALLOC_ZVAL(key); + INIT_PZVAL(key); + switch (zend_hash_get_current_key_ex(fe_ht, &str_key, &str_key_len, &int_key, 1, NULL)) { + case HASH_KEY_IS_STRING: + key->value.str.val = str_key; + key->value.str.len = str_key_len-1; + key->type = IS_STRING; + break; + case HASH_KEY_IS_LONG: + key->value.lval = int_key; + key->type = IS_LONG; + break; + EMPTY_SWITCH_DEFAULT_CASE() + } + zend_hash_index_update(result->value.ht, 1, &key, sizeof(zval *), NULL); } - zend_hash_index_update(result->value.ht, 1, &key, sizeof(zval *), NULL); zend_hash_move_forward(fe_ht); } NEXT_OPCODE(); http://cvs.php.net/diff.php/Zend/zend_language_parser.y?r1=1.23&r2=1.23.4.1&ty=u Index: Zend/zend_language_parser.y diff -u Zend/zend_language_parser.y:1.23 Zend/zend_language_parser.y:1.23.4.1 --- Zend/zend_language_parser.y:1.23 Sun Aug 4 02:39:44 2002 +++ Zend/zend_language_parser.y Fri Sep 24 09:15:15 2004 @@ -199,8 +199,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 '(' w_cvar T_AS { zend_do_foreach_begin(&$1, &$3, &$2, &$4, 1 TSRMLS_CC); } w_cvar foreach_optional_arg ')' { zend_do_foreach_cont(&$6, &$7, &$4 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_cvar foreach_optional_arg ')' { zend_do_foreach_cont(&$6, &$7, &$4 TSRMLS_CC); } foreach_statement { zend_do_foreach_end(&$1, &$2 TSRMLS_CC); } + | T_FOREACH '(' w_cvar T_AS { zend_do_foreach_begin(&$1, &$3, &$2, &$4, 1 TSRMLS_CC); } w_cvar 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_cvar foreach_optional_arg ')' { zend_do_foreach_cont(&$6, &$7, &$4, &$1 TSRMLS_CC); } foreach_statement { zend_do_foreach_end(&$1, &$2 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 */ ;
« previous php.zend-engine.cvs (#3021) next »