Skip to content

Commit ec4913d

Browse files
committed
[WIP] Improve performance of array_walk()
We never need to use refcounted copies for arguments because the copy to the call frame already increments the refcount.
1 parent c262045 commit ec4913d

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

ext/standard/array.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ static zend_result php_array_walk(
14571457
/* Set up known arguments */
14581458
ZVAL_UNDEF(&args[1]);
14591459
if (userdata) {
1460-
ZVAL_COPY(&args[2], userdata);
1460+
ZVAL_COPY_VALUE(&args[2], userdata);
14611461
}
14621462

14631463
fci.retval = &retval;
@@ -1531,21 +1531,16 @@ static zend_result php_array_walk(
15311531
}
15321532
zval_ptr_dtor(&ref);
15331533
} else {
1534-
ZVAL_COPY(&args[0], zv);
1534+
ZVAL_COPY_VALUE(&args[0], zv);
15351535

15361536
/* Call the userland function */
15371537
result = zend_call_function(&fci, &context->fci_cache);
15381538
if (result == SUCCESS) {
15391539
zval_ptr_dtor(&retval);
15401540
}
1541-
1542-
zval_ptr_dtor(&args[0]);
15431541
}
15441542

1545-
if (Z_TYPE(args[1]) != IS_UNDEF) {
1546-
zval_ptr_dtor(&args[1]);
1547-
ZVAL_UNDEF(&args[1]);
1548-
}
1543+
zval_ptr_dtor_str(&args[1]);
15491544

15501545
if (result == FAILURE) {
15511546
break;
@@ -1565,9 +1560,6 @@ static zend_result php_array_walk(
15651560
}
15661561
} while (!EG(exception));
15671562

1568-
if (userdata) {
1569-
zval_ptr_dtor(&args[2]);
1570-
}
15711563
zend_hash_iterator_del(ht_iter);
15721564
return result;
15731565
}

0 commit comments

Comments
 (0)