From 8f9626c0f7abef1974465d1d1db3e7914c689154 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 17 Sep 2023 13:50:19 +0200 Subject: [PATCH] Simplify php_sxe_count_elements_helper() by using non-destructive iterator reset --- ext/simplexml/simplexml.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 7a1e7fcb67a..d304cb77509 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1873,15 +1873,9 @@ 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) { @@ -1889,11 +1883,6 @@ static zend_result php_sxe_count_elements_helper(php_sxe_object *sxe, zend_long 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; } /* }}} */