Skip to content

Commit d456d25

Browse files
authored
Get rid of temporary in array_push (#18181)
This only makes a very very small improvement in performance, but the code size on x86-64 decreases from 357 bytes to 296 bytes.
1 parent 73c2e3c commit d456d25

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

ext/standard/array.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -3502,8 +3502,7 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H
35023502
PHP_FUNCTION(array_push)
35033503
{
35043504
zval *args, /* Function arguments array */
3505-
*stack, /* Input array */
3506-
new_var; /* Variable to be pushed */
3505+
*stack; /* Input array */
35073506
uint32_t argc; /* Number of function arguments */
35083507

35093508

@@ -3514,10 +3513,10 @@ PHP_FUNCTION(array_push)
35143513

35153514
/* For each subsequent argument, make it a reference, increase refcount, and add it to the end of the array */
35163515
for (uint32_t i = 0; i < argc; i++) {
3517-
ZVAL_COPY(&new_var, &args[i]);
3516+
Z_TRY_ADDREF(args[i]);
35183517

3519-
if (zend_hash_next_index_insert(Z_ARRVAL_P(stack), &new_var) == NULL) {
3520-
Z_TRY_DELREF(new_var);
3518+
if (zend_hash_next_index_insert(Z_ARRVAL_P(stack), &args[i]) == NULL) {
3519+
Z_TRY_DELREF(args[i]);
35213520
zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied");
35223521
RETURN_THROWS();
35233522
}

0 commit comments

Comments
 (0)