diff --git a/UPGRADING b/UPGRADING index 858e1cffa953..b0c30bc71457 100644 --- a/UPGRADING +++ b/UPGRADING @@ -125,3 +125,4 @@ PHP 8.6 UPGRADE NOTES - Standard: . Improved performance of array_fill_keys(). + . Improved performance of array_walk(). diff --git a/ext/standard/array.c b/ext/standard/array.c index 32d28fe70220..d1a7996ea6b2 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1457,7 +1457,7 @@ static zend_result php_array_walk( /* Set up known arguments */ ZVAL_UNDEF(&args[1]); if (userdata) { - ZVAL_COPY(&args[2], userdata); + ZVAL_COPY_VALUE(&args[2], userdata); } fci.retval = &retval; @@ -1531,21 +1531,14 @@ static zend_result php_array_walk( } zval_ptr_dtor(&ref); } else { - ZVAL_COPY(&args[0], zv); + ZVAL_COPY_VALUE(&args[0], zv); /* Call the userland function */ result = zend_call_function(&fci, &context->fci_cache); - if (result == SUCCESS) { - zval_ptr_dtor(&retval); - } - - zval_ptr_dtor(&args[0]); + zval_ptr_dtor(&retval); } - if (Z_TYPE(args[1]) != IS_UNDEF) { - zval_ptr_dtor(&args[1]); - ZVAL_UNDEF(&args[1]); - } + zval_ptr_dtor_str(&args[1]); if (result == FAILURE) { break; @@ -1565,9 +1558,6 @@ static zend_result php_array_walk( } } while (!EG(exception)); - if (userdata) { - zval_ptr_dtor(&args[2]); - } zend_hash_iterator_del(ht_iter); return result; }