Skip to content

Commit f485c84

Browse files
committed
Don't always separate splice replacement array
Only perform separation when a typecast is done. Avoids doing a full hash copy in many cases.
1 parent 22d3eb3 commit f485c84

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

ext/standard/array.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,7 @@ PHP_FUNCTION(array_unshift)
19481948
PHP_FUNCTION(array_splice)
19491949
{
19501950
zval *array, /* Input array */
1951-
*repl_array = NULL, /* Replacement array */
1951+
**repl_array = NULL, /* Replacement array */
19521952
***repl = NULL; /* Replacement elements */
19531953
HashTable *rem_hash = NULL; /* Removed elements' hash */
19541954
Bucket *p; /* Bucket used for traversing hash */
@@ -1958,7 +1958,7 @@ PHP_FUNCTION(array_splice)
19581958
repl_num = 0; /* Number of replacement elements */
19591959
int num_in; /* Number of elements in the input array */
19601960

1961-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|lz/", &array, &offset, &length, &repl_array) == FAILURE) {
1961+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|lZ", &array, &offset, &length, &repl_array) == FAILURE) {
19621962
return;
19631963
}
19641964

@@ -1970,12 +1970,12 @@ PHP_FUNCTION(array_splice)
19701970

19711971
if (repl_array) {
19721972
/* Make sure the last argument, if passed, is an array */
1973-
convert_to_array(repl_array);
1973+
convert_to_array_ex(repl_array);
19741974

19751975
/* Create the array of replacement elements */
1976-
repl_num = zend_hash_num_elements(Z_ARRVAL_P(repl_array));
1976+
repl_num = zend_hash_num_elements(Z_ARRVAL_PP(repl_array));
19771977
repl = (zval ***)safe_emalloc(repl_num, sizeof(zval **), 0);
1978-
for (p = Z_ARRVAL_P(repl_array)->pListHead, i = 0; p; p = p->pListNext, i++) {
1978+
for (p = Z_ARRVAL_PP(repl_array)->pListHead, i = 0; p; p = p->pListNext, i++) {
19791979
repl[i] = ((zval **)p->pData);
19801980
}
19811981
}

0 commit comments

Comments
 (0)