File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -3081,11 +3081,25 @@ static zend_result spl_iterator_zip_valid(zend_object_iterator *iter)
30813081 return SUCCESS ;
30823082}
30833083
3084+ /* Invariant: returned array is packed and has all UNDEF elements. */
30843085static zend_array * spl_iterator_zip_reset_array (spl_zip_iterator * zip_iterator )
30853086{
30863087 zval * array_zv = & zip_iterator -> intern .data ;
30873088
3088- // TODO: optimize: reuse array if RC1
3089+ /* Reuse array if it's RC1 */
3090+ if (!Z_ISUNDEF_P (array_zv ) && Z_REFCOUNT_P (array_zv ) == 1 ) {
3091+ zend_array * array = Z_ARR_P (array_zv );
3092+ if (HT_IS_PACKED (array )
3093+ && array -> nNumUsed == zip_iterator -> iterator_count
3094+ && array -> nNumOfElements == zip_iterator -> iterator_count ) {
3095+ array -> nNextFreeElement = zip_iterator -> iterator_count ;
3096+ for (uint32_t i = 0 ; i < zip_iterator -> iterator_count ; i ++ ) {
3097+ zval_ptr_dtor (& array -> arPacked [i ]);
3098+ ZVAL_UNDEF (& array -> arPacked [i ]);
3099+ }
3100+ return array ;
3101+ }
3102+ }
30893103
30903104 zval_ptr_dtor (array_zv );
30913105
You can’t perform that action at this time.
0 commit comments