Skip to content

Commit 82f6f6d

Browse files
committed
Fixed bug #81090
For concatenation, the in-place variant can be much more efficient, because it will reallocate the string in-place. Special-case the typed property compound assignment code for the case where we concatenate to a string, in which case we know that the result will also be a string, and we don't need the type check anyway.
1 parent 4ab434f commit 82f6f6d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ PHP NEWS
55
- Core:
66
. Fixed bug #81068 (Double free in realpath_cache_clean()). (Dimitry Andric)
77
. Fixed bug #76359 (open_basedir bypass through adding ".."). (cmb)
8+
. Fixed bug #81090 (Typed property performance degradation with .= operator).
9+
(Nikita)
810

911
- Standard:
1012
. Fixed bug #81048 (phpinfo(INFO_VARIABLES) "Array to string conversion").

Zend/zend_execute.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,13 @@ static zend_never_inline void zend_binary_assign_op_typed_ref(zend_reference *re
13541354
{
13551355
zval z_copy;
13561356

1357+
/* Make sure that in-place concatenation is used if the LHS is a string. */
1358+
if (opline->extended_value == ZEND_CONCAT && Z_TYPE(ref->val) == IS_STRING) {
1359+
concat_function(&ref->val, &ref->val, value);
1360+
ZEND_ASSERT(Z_TYPE(ref->val) == IS_STRING && "Concat should return string");
1361+
return;
1362+
}
1363+
13571364
zend_binary_op(&z_copy, &ref->val, value OPLINE_CC);
13581365
if (EXPECTED(zend_verify_ref_assignable_zval(ref, &z_copy, EX_USES_STRICT_TYPES()))) {
13591366
zval_ptr_dtor(&ref->val);
@@ -1367,6 +1374,13 @@ static zend_never_inline void zend_binary_assign_op_typed_prop(zend_property_inf
13671374
{
13681375
zval z_copy;
13691376

1377+
/* Make sure that in-place concatenation is used if the LHS is a string. */
1378+
if (opline->extended_value == ZEND_CONCAT && Z_TYPE_P(zptr) == IS_STRING) {
1379+
concat_function(zptr, zptr, value);
1380+
ZEND_ASSERT(Z_TYPE_P(zptr) == IS_STRING && "Concat should return string");
1381+
return;
1382+
}
1383+
13701384
zend_binary_op(&z_copy, zptr, value OPLINE_CC);
13711385
if (EXPECTED(zend_verify_property_type(prop_info, &z_copy, EX_USES_STRICT_TYPES()))) {
13721386
zval_ptr_dtor(zptr);

0 commit comments

Comments
 (0)