Skip to content

Commit f265f80

Browse files
committed
Combine helpers into any() and all(), modernize for php 8
1 parent e98ca8c commit f265f80

18 files changed

+531
-481
lines changed

build/gen_stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public function toTypeCode() {
112112
return "IS_VOID";
113113
case "callable":
114114
return "IS_CALLABLE";
115+
case "iterable":
116+
return "IS_ITERABLE";
115117
case "mixed":
116118
return "IS_MIXED";
117119
default:

ext/spl/spl_iterators.c

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -3166,89 +3166,6 @@ PHP_FUNCTION(iterator_apply)
31663166
}
31673167
/* }}} */
31683168

3169-
typedef struct {
3170-
zval *obj;
3171-
int stop_value;
3172-
int result;
3173-
int found;
3174-
zend_fcall_info fci;
3175-
zend_fcall_info_cache fcc;
3176-
} spl_iterator_until_info;
3177-
3178-
static int spl_iterator_func_until(zend_object_iterator *iter, void *puser) /* {{{ */
3179-
{
3180-
zval args[2];
3181-
zval key;
3182-
zend_fcall_info fci;
3183-
zval retval;
3184-
spl_iterator_until_info *until_info = (spl_iterator_until_info*) puser;
3185-
int result;
3186-
3187-
ZVAL_COPY(&args[0], iter->funcs->get_current_data(iter));
3188-
iter->funcs->get_current_key(iter, &key);
3189-
ZVAL_COPY(&args[1], &key);
3190-
3191-
fci = until_info->fci;
3192-
fci.param_count = 2;
3193-
fci.params = args;
3194-
fci.retval = &retval;
3195-
fci.no_separation = 0;
3196-
3197-
result = zend_call_function(&fci, &until_info->fcc);
3198-
zval_ptr_dtor(&args[0]);
3199-
zval_ptr_dtor(&args[1]);
3200-
if (result == FAILURE) {
3201-
until_info->result = FAILURE;
3202-
return ZEND_HASH_APPLY_STOP;
3203-
}
3204-
3205-
if (zend_is_true(&retval) == until_info->stop_value) {
3206-
until_info->found = 1;
3207-
return ZEND_HASH_APPLY_STOP;
3208-
}
3209-
return ZEND_HASH_APPLY_KEEP;
3210-
}
3211-
/* }}} */
3212-
3213-
static inline void php_iterator_until(INTERNAL_FUNCTION_PARAMETERS, int stop_value) /* {{{ */
3214-
{
3215-
spl_iterator_until_info until_info;
3216-
3217-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Of", &until_info.obj, zend_ce_traversable, &until_info.fci, &until_info.fcc) == FAILURE) {
3218-
return;
3219-
}
3220-
3221-
until_info.stop_value = stop_value;
3222-
until_info.result = SUCCESS;
3223-
until_info.found = 0;
3224-
3225-
if (spl_iterator_apply(until_info.obj, spl_iterator_func_until, (void*)&until_info) == SUCCESS && until_info.result == SUCCESS) {
3226-
RETURN_BOOL(!(until_info.found ^ stop_value));
3227-
}
3228-
}
3229-
/* }}} */
3230-
3231-
/* {{{ proto bool iterator_every(Traversable iterator, mixed predicate)
3232-
Determines whether the predicate holds for all elements in the iterator */
3233-
PHP_FUNCTION(iterator_every)
3234-
{
3235-
php_iterator_until(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
3236-
}
3237-
/* }}} */
3238-
3239-
/* {{{ proto bool iterator_any(Traversable iterator, mixed predicate)
3240-
Determines whether the predicate holds for at least one element in the iterator */
3241-
PHP_FUNCTION(iterator_any)
3242-
{
3243-
php_iterator_until(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
3244-
}
3245-
/* }}} */
3246-
3247-
static const zend_function_entry spl_funcs_OuterIterator[] = {
3248-
SPL_ABSTRACT_ME(OuterIterator, getInnerIterator, arginfo_recursive_it_void)
3249-
PHP_FE_END
3250-
};
3251-
32523169
/* {{{ PHP_MINIT_FUNCTION(spl_iterators) */
32533170
PHP_MINIT_FUNCTION(spl_iterators)
32543171
{

ext/spl/spl_iterators.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ PHP_MINIT_FUNCTION(spl_iterators);
5555
PHP_FUNCTION(iterator_to_array);
5656
PHP_FUNCTION(iterator_count);
5757
PHP_FUNCTION(iterator_apply);
58-
PHP_FUNCTION(iterator_every);
59-
PHP_FUNCTION(iterator_any);
6058

6159
typedef enum {
6260
DIT_Default = 0,

ext/spl/tests/iterator_any_001.phpt

Lines changed: 0 additions & 12 deletions
This file was deleted.

ext/spl/tests/iterator_any_002.phpt

Lines changed: 0 additions & 12 deletions
This file was deleted.

ext/spl/tests/iterator_any_003.phpt

Lines changed: 0 additions & 72 deletions
This file was deleted.

ext/spl/tests/iterator_every_001.phpt

Lines changed: 0 additions & 12 deletions
This file was deleted.

ext/spl/tests/iterator_every_002.phpt

Lines changed: 0 additions & 12 deletions
This file was deleted.

ext/spl/tests/iterator_every_003.phpt

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)