Skip to content

Commit 8c2c694

Browse files
committed
Replace always-false attribute type check with assertion
The type will always be XML_ATTRIBUTE_NODE by construction via php_dom_create_object, no need to check the type. Use an assertion instead. This simplifies code and reasoning about error conditions.
1 parent 50ca242 commit 8c2c694

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

ext/dom/element.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,7 @@ PHP_METHOD(DOMElement, setAttributeNode)
520520

521521
DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);
522522

523-
if (attrp->type != XML_ATTRIBUTE_NODE) {
524-
zend_argument_value_error(1, "must have the node attribute");
525-
RETURN_THROWS();
526-
}
523+
ZEND_ASSERT(attrp->type == XML_ATTRIBUTE_NODE);
527524

528525
if (!(attrp->doc == NULL || attrp->doc == nodep->doc)) {
529526
php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document));
@@ -581,7 +578,9 @@ PHP_METHOD(DOMElement, removeAttributeNode)
581578

582579
DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);
583580

584-
if (attrp->type != XML_ATTRIBUTE_NODE || attrp->parent != nodep) {
581+
ZEND_ASSERT(attrp->type == XML_ATTRIBUTE_NODE);
582+
583+
if (attrp->parent != nodep) {
585584
php_dom_throw_error(NOT_FOUND_ERR, dom_get_strict_error(intern->document));
586585
RETURN_FALSE;
587586
}

0 commit comments

Comments
 (0)