Skip to content

Commit 8fd7a48

Browse files
committed
Optimize checks in for DOMParentNode
If we check the list with dom_sanity_check_node_list_for_insertion() before dom_is_node_in_list(), then we don't have to check the object type anymore in dom_is_node_in_list(), because dom_sanity_check_node_list_for_insertion() will have already done that.
1 parent cb927e0 commit 8fd7a48

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

ext/dom/parentnode.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,8 @@ static bool dom_is_node_in_list(const zval *nodes, uint32_t nodesc, const xmlNod
128128
{
129129
for (uint32_t i = 0; i < nodesc; i++) {
130130
if (Z_TYPE(nodes[i]) == IS_OBJECT) {
131-
const zend_class_entry *ce = Z_OBJCE(nodes[i]);
132-
133-
if (instanceof_function(ce, dom_node_class_entry)) {
134-
if (dom_object_get_node(Z_DOMOBJ_P(nodes + i)) == node_to_find) {
135-
return true;
136-
}
131+
if (dom_object_get_node(Z_DOMOBJ_P(nodes + i)) == node_to_find) {
132+
return true;
137133
}
138134
}
139135
}
@@ -398,6 +394,10 @@ void dom_parent_node_after(dom_object *context, zval *nodes, uint32_t nodesc)
398394
return;
399395
}
400396

397+
if (UNEXPECTED(dom_sanity_check_node_list_for_insertion(context->document, parentNode, nodes, nodesc) != SUCCESS)) {
398+
return;
399+
}
400+
401401
/* Spec step 3: find first following child not in nodes; otherwise null */
402402
xmlNodePtr viable_next_sibling = prevsib->next;
403403
while (viable_next_sibling) {
@@ -409,10 +409,6 @@ void dom_parent_node_after(dom_object *context, zval *nodes, uint32_t nodesc)
409409

410410
doc = prevsib->doc;
411411

412-
if (UNEXPECTED(dom_sanity_check_node_list_for_insertion(context->document, parentNode, nodes, nodesc) != SUCCESS)) {
413-
return;
414-
}
415-
416412
php_libxml_invalidate_node_list_cache_from_doc(doc);
417413

418414
/* Spec step 4: convert nodes into fragment */
@@ -455,6 +451,10 @@ void dom_parent_node_before(dom_object *context, zval *nodes, uint32_t nodesc)
455451
return;
456452
}
457453

454+
if (UNEXPECTED(dom_sanity_check_node_list_for_insertion(context->document, parentNode, nodes, nodesc) != SUCCESS)) {
455+
return;
456+
}
457+
458458
/* Spec step 3: find first following child not in nodes; otherwise null */
459459
xmlNodePtr viable_previous_sibling = nextsib->prev;
460460
while (viable_previous_sibling) {
@@ -466,10 +466,6 @@ void dom_parent_node_before(dom_object *context, zval *nodes, uint32_t nodesc)
466466

467467
doc = nextsib->doc;
468468

469-
if (UNEXPECTED(dom_sanity_check_node_list_for_insertion(context->document, parentNode, nodes, nodesc) != SUCCESS)) {
470-
return;
471-
}
472-
473469
php_libxml_invalidate_node_list_cache_from_doc(doc);
474470

475471
/* Spec step 4: convert nodes into fragment */
@@ -562,6 +558,10 @@ void dom_child_replace_with(dom_object *context, zval *nodes, uint32_t nodesc)
562558
return;
563559
}
564560

561+
if (UNEXPECTED(dom_sanity_check_node_list_for_insertion(context->document, parentNode, nodes, nodesc) != SUCCESS)) {
562+
return;
563+
}
564+
565565
/* Spec step 3: find first following child not in nodes; otherwise null */
566566
xmlNodePtr viable_next_sibling = child->next;
567567
while (viable_next_sibling) {
@@ -571,10 +571,6 @@ void dom_child_replace_with(dom_object *context, zval *nodes, uint32_t nodesc)
571571
viable_next_sibling = viable_next_sibling->next;
572572
}
573573

574-
if (UNEXPECTED(dom_sanity_check_node_list_for_insertion(context->document, parentNode, nodes, nodesc) != SUCCESS)) {
575-
return;
576-
}
577-
578574
php_libxml_invalidate_node_list_cache_from_doc(context->document->ptr);
579575

580576
/* Spec step 4: convert nodes into fragment */

0 commit comments

Comments
 (0)