From fbd1a1a450766cafba7f1d6bfad88a5eec8f063f Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 29 Mar 2025 14:37:14 +0100 Subject: [PATCH] Get rid of temporary in array_push This only makes a very very small improvement in performance, but the code size on x86-64 decreases from 357 bytes to 296 bytes. --- ext/standard/array.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ext/standard/array.c b/ext/standard/array.c index 994e0ad34a8cb..378fc63894448 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -3502,8 +3502,7 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H PHP_FUNCTION(array_push) { zval *args, /* Function arguments array */ - *stack, /* Input array */ - new_var; /* Variable to be pushed */ + *stack; /* Input array */ uint32_t argc; /* Number of function arguments */ @@ -3514,10 +3513,10 @@ PHP_FUNCTION(array_push) /* For each subsequent argument, make it a reference, increase refcount, and add it to the end of the array */ for (uint32_t i = 0; i < argc; i++) { - ZVAL_COPY(&new_var, &args[i]); + Z_TRY_ADDREF(args[i]); - if (zend_hash_next_index_insert(Z_ARRVAL_P(stack), &new_var) == NULL) { - Z_TRY_DELREF(new_var); + if (zend_hash_next_index_insert(Z_ARRVAL_P(stack), &args[i]) == NULL) { + Z_TRY_DELREF(args[i]); zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied"); RETURN_THROWS(); }