Skip to content

Commit

Permalink
Implement RC1 optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsdos committed Dec 11, 2024
1 parent 6f5a636 commit 1fc39e1
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ext/spl/spl_iterators.c
Original file line number Diff line number Diff line change
Expand Up @@ -3081,11 +3081,25 @@ static zend_result spl_iterator_zip_valid(zend_object_iterator *iter)
return SUCCESS;
}

/* Invariant: returned array is packed and has all UNDEF elements. */
static zend_array *spl_iterator_zip_reset_array(spl_zip_iterator *zip_iterator)
{
zval *array_zv = &zip_iterator->intern.data;

// TODO: optimize: reuse array if RC1
/* Reuse array if it's RC1 */
if (!Z_ISUNDEF_P(array_zv) && Z_REFCOUNT_P(array_zv) == 1) {
zend_array *array = Z_ARR_P(array_zv);
if (HT_IS_PACKED(array)
&& array->nNumUsed == zip_iterator->iterator_count
&& array->nNumOfElements == zip_iterator->iterator_count) {
array->nNextFreeElement = zip_iterator->iterator_count;
for (uint32_t i = 0; i < zip_iterator->iterator_count; i++) {
zval_ptr_dtor(&array->arPacked[i]);
ZVAL_UNDEF(&array->arPacked[i]);
}
return array;
}
}

zval_ptr_dtor(array_zv);

Expand Down

0 comments on commit 1fc39e1

Please sign in to comment.