]> granicus.if.org Git - php/commitdiff
Avoid reallocations when concatenate with empty string
authorDmitry Stogov <dmitry@zend.com>
Thu, 26 Oct 2017 06:45:02 +0000 (09:45 +0300)
committerDmitry Stogov <dmitry@zend.com>
Thu, 26 Oct 2017 06:45:02 +0000 (09:45 +0300)
Zend/zend_operators.c

index 5270b6b39a995cbdb594406e80a9055edaf62169..1449405b43483c1d18083316f21bb449a10e4e32 100644 (file)
@@ -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;