summaryrefslogtreecommitdiff
path: root/Zend/zend_vm_execute.h
diff options
context:
space:
mode:
authorTyson Andre <tysonandre775@hotmail.com>2020-04-19 11:53:36 -0400
committerTyson Andre <tysonandre775@hotmail.com>2020-04-19 17:31:18 -0400
commitcd56395d4779582506b35c11e6dcd415112113d9 (patch)
tree5b653ef49b54e38357b51b9786f09b76310884bf /Zend/zend_vm_execute.h
parent928b25cd6e6a6c6f039b22e7ff55c1a67339256c (diff)
downloadphp-git-cd56395d4779582506b35c11e6dcd415112113d9.tar.gz
Speed up ZEND_SWITCH_STRING/ZEND_SWITCH_LONG for wrong type
This has the minor benefit of avoiding loading the address of the jump table when the expression for the switch isn't a string/long. gcc doesn't seem to optimize that. The previous function body is the original implementation: ad8652818a5 ``` // Before: 0.267s, after: 0.265s function test_switch($x) { for ($i = 0; $i < 10000000; $i++) { switch ($x) { case 'a': case 'b': echo "i=$i\n"; } } } test_switch(null); ``` Closes GH-5419
Diffstat (limited to 'Zend/zend_vm_execute.h')
-rw-r--r--Zend/zend_vm_execute.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index 33e97f2b04..346dbec656 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -6454,7 +6454,6 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SWITCH_LONG_SPEC_
HashTable *jumptable;
op = RT_CONSTANT(opline, opline->op1);
- jumptable = Z_ARRVAL_P(RT_CONSTANT(opline, opline->op2));
if (Z_TYPE_P(op) != IS_LONG) {
ZVAL_DEREF(op);
@@ -6464,6 +6463,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SWITCH_LONG_SPEC_
}
}
+ jumptable = Z_ARRVAL_P(RT_CONSTANT(opline, opline->op2));
jump_zv = zend_hash_index_find(jumptable, Z_LVAL_P(op));
if (jump_zv != NULL) {
ZEND_VM_SET_RELATIVE_OPCODE(opline, Z_LVAL_P(jump_zv));
@@ -6482,7 +6482,6 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SWITCH_STRING_SPE
HashTable *jumptable;
op = RT_CONSTANT(opline, opline->op1);
- jumptable = Z_ARRVAL_P(RT_CONSTANT(opline, opline->op2));
if (Z_TYPE_P(op) != IS_STRING) {
if (IS_CONST == IS_CONST) {
@@ -6497,6 +6496,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SWITCH_STRING_SPE
}
}
+ jumptable = Z_ARRVAL_P(RT_CONSTANT(opline, opline->op2));
jump_zv = zend_hash_find_ex(jumptable, Z_STR_P(op), IS_CONST == IS_CONST);
if (jump_zv != NULL) {
ZEND_VM_SET_RELATIVE_OPCODE(opline, Z_LVAL_P(jump_zv));
@@ -11316,7 +11316,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SWITCH_LONG_SPEC_TMPVARCV_CONS
HashTable *jumptable;
op = EX_VAR(opline->op1.var);
- jumptable = Z_ARRVAL_P(RT_CONSTANT(opline, opline->op2));
if (Z_TYPE_P(op) != IS_LONG) {
ZVAL_DEREF(op);
@@ -11326,6 +11325,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SWITCH_LONG_SPEC_TMPVARCV_CONS
}
}
+ jumptable = Z_ARRVAL_P(RT_CONSTANT(opline, opline->op2));
jump_zv = zend_hash_index_find(jumptable, Z_LVAL_P(op));
if (jump_zv != NULL) {
ZEND_VM_SET_RELATIVE_OPCODE(opline, Z_LVAL_P(jump_zv));
@@ -11344,7 +11344,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SWITCH_STRING_SPEC_TMPVARCV_CO
HashTable *jumptable;
op = EX_VAR(opline->op1.var);
- jumptable = Z_ARRVAL_P(RT_CONSTANT(opline, opline->op2));
if (Z_TYPE_P(op) != IS_STRING) {
if ((IS_TMP_VAR|IS_VAR|IS_CV) == IS_CONST) {
@@ -11359,6 +11358,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SWITCH_STRING_SPEC_TMPVARCV_CO
}
}
+ jumptable = Z_ARRVAL_P(RT_CONSTANT(opline, opline->op2));
jump_zv = zend_hash_find_ex(jumptable, Z_STR_P(op), (IS_TMP_VAR|IS_VAR|IS_CV) == IS_CONST);
if (jump_zv != NULL) {
ZEND_VM_SET_RELATIVE_OPCODE(opline, Z_LVAL_P(jump_zv));