cvs: ZendEngine2 / zend_compile.c
| From: | Andi Gutmans | Date: | Mon, 23 Aug 2004 20:16:35 +0000 |
| Subject: | cvs: ZendEngine2 / zend_compile.c | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-2890@lists.php.net to get a copy of this message | ||
andi Mon Aug 23 16:16:35 2004 EDT
Modified files:
/ZendEngine2 zend_compile.c
Log:
- Improve performance of switch()
http://cvs.php.net/diff.php/ZendEngine2/zend_compile.c?r1=1.579&r2=1.580&ty=u
Index: ZendEngine2/zend_compile.c
diff -u ZendEngine2/zend_compile.c:1.579 ZendEngine2/zend_compile.c:1.580
--- ZendEngine2/zend_compile.c:1.579 Fri Aug 20 20:00:16 2004
+++ ZendEngine2/zend_compile.c Mon Aug 23 16:16:35 2004
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_compile.c,v 1.579 2004/08/21 00:00:16 pollita Exp $ */
+/* $Id: zend_compile.c,v 1.580 2004/08/23 20:16:35 andi Exp $ */
#include "zend_language_parser.h"
#include "zend.h"
@@ -2330,20 +2330,9 @@
zend_switch_entry switch_entry;
zend_op *opline;
- /* Initialize the conditional value */
- opline = get_next_op(CG(active_op_array) TSRMLS_CC);
- opline->opcode = ZEND_BOOL;
- opline->result.u.var = get_temporary_variable(CG(active_op_array));
- opline->result.op_type = IS_TMP_VAR;
- opline->op1.op_type = IS_CONST;
- opline->op1.u.constant.type = IS_BOOL;
- opline->op1.u.constant.value.lval = 0;
- INIT_PZVAL(&opline->op1.u.constant);
- SET_UNUSED(opline->op2);
-
switch_entry.cond = *cond;
switch_entry.default_case = -1;
- switch_entry.control_var = opline->result.u.var;
+ switch_entry.control_var = -1;
zend_stack_push(&CG(switch_cond_stack), (void *) &switch_entry, sizeof(switch_entry));
do_begin_loop(TSRMLS_C);
@@ -2366,17 +2355,6 @@
CG(active_op_array)->opcodes[case_list->u.opline_num].op1.u.opline_num = next_op_number;
}
- /* add code to jmp to default case */
- if (switch_entry_ptr->default_case != -1) {
- opline = get_next_op(CG(active_op_array) TSRMLS_CC);
- opline->opcode = ZEND_JMPZ;
- opline->op1.op_type = IS_TMP_VAR;
- opline->op1.u.var = switch_entry_ptr->control_var;
- opline->op2.u.opline_num = switch_entry_ptr->default_case;
- SET_UNUSED(opline->op2);
- }
-
-
/* remember break/continue loop information */
CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].cont =
CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].brk =
get_next_op_number(CG(active_op_array));
CG(active_op_array)->current_brk_cont =
CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].parent;
@@ -2407,6 +2385,9 @@
zend_stack_top(&CG(switch_cond_stack), (void **) &switch_entry_ptr);
+ if (switch_entry_ptr->control_var == -1) {
+ switch_entry_ptr->control_var = get_temporary_variable(CG(active_op_array));
+ }
opline->opcode = ZEND_CASE;
opline->result.u.var = switch_entry_ptr->control_var;
opline->result.op_type = IS_TMP_VAR;
@@ -2442,13 +2423,8 @@
SET_UNUSED(opline->op2);
result->u.opline_num = next_op_number;
- switch (CG(active_op_array)->opcodes[case_token->u.opline_num].opcode) {
- case ZEND_JMP:
- CG(active_op_array)->opcodes[case_token->u.opline_num].op1.u.opline_num =
get_next_op_number(CG(active_op_array));
- break;
- case ZEND_JMPZ:
- CG(active_op_array)->opcodes[case_token->u.opline_num].op2.u.opline_num =
get_next_op_number(CG(active_op_array));
- break;
+ if (case_token->u.opline_num != -1) {
+ CG(active_op_array)->opcodes[case_token->u.opline_num].op2.u.opline_num =
get_next_op_number(CG(active_op_array));
}
}
@@ -2457,32 +2433,16 @@
void zend_do_default_before_statement(znode *case_list, znode *default_token TSRMLS_DC)
{
int next_op_number = get_next_op_number(CG(active_op_array));
- zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
zend_switch_entry *switch_entry_ptr;
zend_stack_top(&CG(switch_cond_stack), (void **) &switch_entry_ptr);
- opline->opcode = ZEND_JMP;
- SET_UNUSED(opline->op1);
- SET_UNUSED(opline->op2);
- default_token->u.opline_num = next_op_number;
-
- next_op_number = get_next_op_number(CG(active_op_array));
- opline = get_next_op(CG(active_op_array) TSRMLS_CC);
- opline->opcode = ZEND_BOOL;
- opline->result.u.var = switch_entry_ptr->control_var;
- opline->result.op_type = IS_TMP_VAR;
- opline->op1.op_type = IS_CONST;
- opline->op1.u.constant.type = IS_BOOL;
- opline->op1.u.constant.value.lval = 1;
- INIT_PZVAL(&opline->op1.u.constant);
- SET_UNUSED(opline->op2);
+ default_token->u.opline_num = -1;
switch_entry_ptr->default_case = next_op_number;
if (case_list->op_type==IS_UNUSED) {
return;
}
- next_op_number = get_next_op_number(CG(active_op_array));
CG(active_op_array)->opcodes[case_list->u.opline_num].op1.u.opline_num = next_op_number;
}