From: Dmitry Stogov Date: Thu, 26 Oct 2017 06:45:02 +0000 (+0300) Subject: Avoid reallocations when concatenate with empty string X-Git-Tag: php-7.3.0alpha1~1169 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=886d4d9ca113ea24b373ee7b0fa8b2c5235be9ae;p=php Avoid reallocations when concatenate with empty string --- diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 5270b6b39a..1449405b43 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -1744,7 +1744,18 @@ ZEND_API int ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2) / } } while (0); - { + if (UNEXPECTED(Z_STRLEN_P(op1) == 0)) { + if (EXPECTED(result != op2)) { + if (result == orig_op1) { + zval_dtor(orig_op1); + } + ZVAL_COPY(result, op2); + } + } else if (UNEXPECTED(Z_STRLEN_P(op2) == 0)) { + if (EXPECTED(result != op1)) { + ZVAL_COPY(result, op1); + } + } else { size_t op1_len = Z_STRLEN_P(op1); size_t op2_len = Z_STRLEN_P(op2); size_t result_len = op1_len + op2_len;