Skip to content

Commit 8f9626c

Browse files
committedSep 17, 2023
Simplify php_sxe_count_elements_helper() by using non-destructive iterator reset
1 parent fe98a16 commit 8f9626c

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed
 

‎ext/simplexml/simplexml.c

+1-12
Original file line numberDiff line numberDiff line change
@@ -1873,27 +1873,16 @@ PHP_METHOD(SimpleXMLElement, __toString)
18731873

18741874
static zend_result php_sxe_count_elements_helper(php_sxe_object *sxe, zend_long *count) /* {{{ */
18751875
{
1876-
xmlNodePtr node;
1877-
zval data;
1878-
18791876
*count = 0;
18801877

1881-
ZVAL_COPY_VALUE(&data, &sxe->iter.data);
1882-
ZVAL_UNDEF(&sxe->iter.data);
1883-
1884-
node = php_sxe_reset_iterator(sxe, 0);
1878+
xmlNodePtr node = php_sxe_reset_iterator_no_clear_iter_data(sxe, 0);
18851879

18861880
while (node)
18871881
{
18881882
(*count)++;
18891883
node = php_sxe_iterator_fetch(sxe, node->next, 0);
18901884
}
18911885

1892-
if (!Z_ISUNDEF(sxe->iter.data)) {
1893-
zval_ptr_dtor(&sxe->iter.data);
1894-
}
1895-
ZVAL_COPY_VALUE(&sxe->iter.data, &data);
1896-
18971886
return SUCCESS;
18981887
}
18991888
/* }}} */

0 commit comments

Comments
 (0)
Please sign in to comment.