Skip to content

Commit 7c32e41

Browse files
committed
ext/spl: Refactor iterator_apply() to not rely on an FCI
This reduces the size of the struct from 112 to 56 bytes
1 parent 3de22a8 commit 7c32e41

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

ext/spl/spl_iterators.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3059,9 +3059,9 @@ PHP_FUNCTION(iterator_count)
30593059
/* }}} */
30603060

30613061
typedef struct {
3062-
zend_long count;
3063-
zend_fcall_info fci;
3064-
zend_fcall_info_cache fcc;
3062+
zend_long count;
3063+
HashTable *params_ht;
3064+
zend_fcall_info_cache fcc;
30653065
} spl_iterator_apply_info;
30663066

30673067
static int spl_iterator_func_apply(zend_object_iterator *iter, void *puser) /* {{{ */
@@ -3071,7 +3071,7 @@ static int spl_iterator_func_apply(zend_object_iterator *iter, void *puser) /* {
30713071
int result;
30723072

30733073
apply_info->count++;
3074-
zend_call_function_with_return_value(&apply_info->fci, &apply_info->fcc, &retval);
3074+
zend_call_known_fcc(&apply_info->fcc, &retval, 0, NULL, apply_info->params_ht);
30753075
result = zend_is_true(&retval) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_STOP;
30763076
zval_ptr_dtor(&retval);
30773077
return result;
@@ -3082,18 +3082,25 @@ static int spl_iterator_func_apply(zend_object_iterator *iter, void *puser) /* {
30823082
PHP_FUNCTION(iterator_apply)
30833083
{
30843084
zval *traversable;
3085-
spl_iterator_apply_info apply_info;
3085+
zend_fcall_info dummy_fci;
3086+
spl_iterator_apply_info apply_info = {
3087+
.count = 0,
3088+
.params_ht = NULL,
3089+
.fcc = {},
3090+
};
30863091

30873092
/* The HashTable is used to determine positional arguments */
3088-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Of|h!", &traversable, zend_ce_traversable,
3089-
&apply_info.fci, &apply_info.fcc, &apply_info.fci.named_params) == FAILURE) {
3093+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OF|h!", &traversable, zend_ce_traversable,
3094+
&dummy_fci, &apply_info.fcc, &apply_info.params_ht) == FAILURE) {
3095+
zend_release_fcall_info_cache(&apply_info.fcc);
30903096
RETURN_THROWS();
30913097
}
30923098

3093-
apply_info.count = 0;
30943099
if (spl_iterator_apply(traversable, spl_iterator_func_apply, (void*)&apply_info) == FAILURE) {
3095-
return;
3100+
zend_release_fcall_info_cache(&apply_info.fcc);
3101+
RETURN_THROWS();
30963102
}
3103+
zend_release_fcall_info_cache(&apply_info.fcc);
30973104
RETURN_LONG(apply_info.count);
30983105
}
30993106
/* }}} */

0 commit comments

Comments
 (0)