diff options
| author | Dmitry Stogov <dmitry@zend.com> | 2018-05-03 14:40:18 +0300 |
|---|---|---|
| committer | Dmitry Stogov <dmitry@zend.com> | 2018-05-03 14:40:18 +0300 |
| commit | 1a63fa6ec9b0bacbb726e60c3c212e7d97b518c6 (patch) | |
| tree | 31df39e3dae0107e1837d60fe318dd094d765d10 /Zend/zend_vm_def.h | |
| parent | 5a31e14beba625f1b32d61d6aec85b3df7f023cc (diff) | |
| download | php-git-1a63fa6ec9b0bacbb726e60c3c212e7d97b518c6.tar.gz | |
Implemented Request #76178 (Class constants are slow: they should be inlined at runtime)
Run-time cache is used to eliminate recalculation of constant expression in RECV_INIT opcode (only non reference countable values are cached).
Diffstat (limited to 'Zend/zend_vm_def.h')
| -rw-r--r-- | Zend/zend_vm_def.h | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index cad1ca2ebc..d756e97bc9 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -4724,14 +4724,28 @@ ZEND_VM_HOT_HANDLER(64, ZEND_RECV_INIT, NUM, CONST, CACHE_SLOT) arg_num = opline->op1.num; param = _get_zval_ptr_cv_undef_BP_VAR_W(opline->result.var EXECUTE_DATA_CC); if (arg_num > EX_NUM_ARGS()) { - ZVAL_COPY(param, RT_CONSTANT(opline, opline->op2)); - if (Z_OPT_TYPE_P(param) == IS_CONSTANT_AST) { - SAVE_OPLINE(); - if (UNEXPECTED(zval_update_constant_ex(param, EX(func)->op_array.scope) != SUCCESS)) { - zval_ptr_dtor_nogc(param); - ZVAL_UNDEF(param); - HANDLE_EXCEPTION(); + zval *default_value = RT_CONSTANT(opline, opline->op2); + + if (Z_OPT_TYPE_P(default_value) == IS_CONSTANT_AST) { + zval *cache_val = (zval*)CACHE_ADDR(Z_CACHE_SLOT_P(default_value)); + + /* we keep in cache only not refcounted values */ + if (Z_TYPE_P(cache_val) != IS_UNDEF) { + ZVAL_COPY_VALUE(param, cache_val); + } else { + SAVE_OPLINE(); + ZVAL_COPY(param, default_value); + if (UNEXPECTED(zval_update_constant_ex(param, EX(func)->op_array.scope) != SUCCESS)) { + zval_ptr_dtor_nogc(param); + ZVAL_UNDEF(param); + HANDLE_EXCEPTION(); + } + if (!Z_REFCOUNTED_P(param)) { + ZVAL_COPY_VALUE(cache_val, param); + } } + } else { + ZVAL_COPY(param, default_value); } } |
