Skip to content

Use fast ZPP in very commonly used DOM functions #14077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,19 +525,17 @@ PHP_METHOD(DOMDocument, createDocumentFragment)
*/
PHP_METHOD(DOMDocument, createTextNode)
{
zval *id;
xmlNode *node;
xmlDocPtr docp;
size_t value_len;
dom_object *intern;
char *value;

id = ZEND_THIS;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &value, &value_len) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(value, value_len)
ZEND_PARSE_PARAMETERS_END();

DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
DOM_GET_OBJ(docp, ZEND_THIS, xmlDocPtr, intern);

node = xmlNewDocText(docp, BAD_CAST value);
if (!node) {
Expand Down Expand Up @@ -899,11 +897,12 @@ PHP_METHOD(DOM_Document, createElementNS)
{
xmlDocPtr docp;
dom_object *intern;
zend_string *name = NULL, *uri;
zend_string *name, *uri;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "S!S", &uri, &name) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_STR_OR_NULL(uri)
Z_PARAM_STR(name)
ZEND_PARSE_PARAMETERS_END();

DOM_GET_OBJ(docp, ZEND_THIS, xmlDocPtr, intern);

Expand Down
46 changes: 11 additions & 35 deletions ext/dom/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -1218,16 +1218,15 @@ PHP_METHOD(DOM_Node, replaceChild)
*/
static void dom_node_remove_child(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *node_ce)
{
zval *id, *node;
zval *node;
xmlNodePtr child, nodep;
dom_object *intern, *childobj;

id = ZEND_THIS;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &node, node_ce) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_OBJECT_OF_CLASS(node, node_ce)
ZEND_PARSE_PARAMETERS_END();

DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
DOM_GET_OBJ(nodep, ZEND_THIS, xmlNodePtr, intern);

if (!dom_node_children_valid(nodep)) {
RETURN_FALSE;
Expand Down Expand Up @@ -1420,26 +1419,14 @@ PHP_METHOD(DOM_Node, appendChild)
*/
PHP_METHOD(DOMNode, hasChildNodes)
{
zval *id;
xmlNode *nodep;
dom_object *intern;

id = ZEND_THIS;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_NONE();

DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);

if (!dom_node_children_valid(nodep)) {
RETURN_FALSE;
}
DOM_GET_OBJ(nodep, ZEND_THIS, xmlNodePtr, intern);

if (nodep->children) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
RETURN_BOOL(dom_node_children_valid(nodep) && nodep->children != NULL);
}
/* }}} end dom_node_has_child_nodes */

Expand Down Expand Up @@ -1552,25 +1539,14 @@ Since: DOM Level 2
*/
PHP_METHOD(DOMNode, hasAttributes)
{
zval *id;
xmlNode *nodep;
dom_object *intern;

id = ZEND_THIS;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}

DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
ZEND_PARSE_PARAMETERS_NONE();

if (nodep->type != XML_ELEMENT_NODE)
RETURN_FALSE;
DOM_GET_OBJ(nodep, ZEND_THIS, xmlNodePtr, intern);

if (nodep->properties) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
RETURN_BOOL(nodep->type == XML_ELEMENT_NODE && nodep->properties != NULL);
}
/* }}} end dom_node_has_attributes */

Expand Down
Loading