Skip to content

Commit 51ff37b

Browse files
committed
Factor out dom_fetch_first_iteration_item()
1 parent c18fa43 commit 51ff37b

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

ext/dom/dom_iterators.c

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,26 @@ static void php_dom_iterator_current_key(zend_object_iterator *iter, zval *key)
139139
}
140140
/* }}} */
141141

142+
static xmlNodePtr dom_fetch_first_iteration_item(dom_nnodemap_object *objmap)
143+
{
144+
xmlNodePtr basep = dom_object_get_node(objmap->baseobj);
145+
if (!basep) {
146+
return NULL;
147+
}
148+
if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) {
149+
if (objmap->nodetype == XML_ATTRIBUTE_NODE) {
150+
return (xmlNodePtr) basep->properties;
151+
} else {
152+
return basep->children;
153+
}
154+
} else {
155+
int curindex = 0;
156+
xmlNodePtr nodep = php_dom_first_child_of_container_node(basep);
157+
return dom_get_elements_by_tag_name_ns_raw(
158+
basep, nodep, objmap->ns, objmap->local, objmap->local_lower, &curindex, 0);
159+
}
160+
}
161+
142162
static void php_dom_iterator_move_forward(zend_object_iterator *iter) /* {{{ */
143163
{
144164
xmlNodePtr curnode = NULL;
@@ -219,7 +239,6 @@ zend_object_iterator *php_dom_get_iterator(zend_class_entry *ce, zval *object, i
219239
dom_object *intern;
220240
dom_nnodemap_object *objmap;
221241
xmlNodePtr curnode=NULL;
222-
int curindex = 0;
223242
HashTable *nodeht;
224243
zval *entry;
225244
php_dom_iterator *iterator;
@@ -249,27 +268,13 @@ zend_object_iterator *php_dom_get_iterator(zend_class_entry *ce, zval *object, i
249268
ZVAL_COPY(&iterator->curobj, entry);
250269
}
251270
} else {
252-
xmlNodePtr basep = (xmlNode *)dom_object_get_node(objmap->baseobj);
253-
if (!basep) {
254-
goto err;
255-
}
256-
if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) {
257-
if (objmap->nodetype == XML_ATTRIBUTE_NODE) {
258-
curnode = (xmlNodePtr) basep->properties;
259-
} else {
260-
curnode = (xmlNodePtr) basep->children;
261-
}
262-
} else {
263-
xmlNodePtr nodep = php_dom_first_child_of_container_node(basep);
264-
curnode = dom_get_elements_by_tag_name_ns_raw(
265-
basep, nodep, objmap->ns, objmap->local, objmap->local_lower, &curindex, 0);
266-
}
271+
curnode = dom_fetch_first_iteration_item(objmap);
267272
}
268273
} else {
269274
curnode = php_dom_libxml_hash_iter(objmap, 0);
270275
}
271276
}
272-
err:
277+
273278
if (curnode) {
274279
php_dom_create_object(curnode, &iterator->curobj, objmap->baseobj);
275280
}

0 commit comments

Comments
 (0)