Skip to content

Commit

Permalink
Simplify php_sxe_count_elements_helper() by using non-destructive ite…
Browse files Browse the repository at this point in the history
…rator reset
  • Loading branch information
nielsdos committed Sep 17, 2023
1 parent fe98a16 commit 8f9626c
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions ext/simplexml/simplexml.c
Expand Up @@ -1873,27 +1873,16 @@ PHP_METHOD(SimpleXMLElement, __toString)

static zend_result php_sxe_count_elements_helper(php_sxe_object *sxe, zend_long *count) /* {{{ */
{
xmlNodePtr node;
zval data;

*count = 0;

ZVAL_COPY_VALUE(&data, &sxe->iter.data);
ZVAL_UNDEF(&sxe->iter.data);

node = php_sxe_reset_iterator(sxe, 0);
xmlNodePtr node = php_sxe_reset_iterator_no_clear_iter_data(sxe, 0);

while (node)
{
(*count)++;
node = php_sxe_iterator_fetch(sxe, node->next, 0);
}

if (!Z_ISUNDEF(sxe->iter.data)) {
zval_ptr_dtor(&sxe->iter.data);
}
ZVAL_COPY_VALUE(&sxe->iter.data, &data);

return SUCCESS;
}
/* }}} */
Expand Down

0 comments on commit 8f9626c

Please sign in to comment.