mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
Avoid unnecessary string refcounting in ext/dom (#17889)
This commit is contained in:
parent
618190127e
commit
1eacd4aea0
3 changed files with 12 additions and 14 deletions
|
@ -194,13 +194,12 @@ zend_result dom_document_version_write(dom_object *obj, zval *newval)
|
||||||
{
|
{
|
||||||
DOM_PROP_NODE(xmlDocPtr, docp, obj);
|
DOM_PROP_NODE(xmlDocPtr, docp, obj);
|
||||||
|
|
||||||
/* Cannot fail because the type is either null or a string. */
|
/* Type is ?string */
|
||||||
zend_string *str = zval_get_string(newval);
|
zend_string *str = Z_TYPE_P(newval) == IS_NULL ? ZSTR_EMPTY_ALLOC() : Z_STR_P(newval);
|
||||||
|
|
||||||
if (php_dom_follow_spec_intern(obj)) {
|
if (php_dom_follow_spec_intern(obj)) {
|
||||||
if (!zend_string_equals_literal(str, "1.0") && !zend_string_equals_literal(str, "1.1")) {
|
if (!zend_string_equals_literal(str, "1.0") && !zend_string_equals_literal(str, "1.1")) {
|
||||||
zend_value_error("Invalid XML version");
|
zend_value_error("Invalid XML version");
|
||||||
zend_string_release_ex(str, 0);
|
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,7 +210,6 @@ zend_result dom_document_version_write(dom_object *obj, zval *newval)
|
||||||
|
|
||||||
docp->version = xmlStrdup((const xmlChar *) ZSTR_VAL(str));
|
docp->version = xmlStrdup((const xmlChar *) ZSTR_VAL(str));
|
||||||
|
|
||||||
zend_string_release_ex(str, 0);
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,8 +392,8 @@ zend_result dom_document_document_uri_write(dom_object *obj, zval *newval)
|
||||||
{
|
{
|
||||||
DOM_PROP_NODE(xmlDocPtr, docp, obj);
|
DOM_PROP_NODE(xmlDocPtr, docp, obj);
|
||||||
|
|
||||||
/* Cannot fail because the type is either null or a string. */
|
/* Type is ?string */
|
||||||
zend_string *str = zval_get_string(newval);
|
zend_string *str = Z_TYPE_P(newval) == IS_NULL ? ZSTR_EMPTY_ALLOC() : Z_STR_P(newval);
|
||||||
|
|
||||||
if (docp->URL != NULL) {
|
if (docp->URL != NULL) {
|
||||||
xmlFree(BAD_CAST docp->URL);
|
xmlFree(BAD_CAST docp->URL);
|
||||||
|
@ -403,7 +401,6 @@ zend_result dom_document_document_uri_write(dom_object *obj, zval *newval)
|
||||||
|
|
||||||
docp->URL = xmlStrdup((const xmlChar *) ZSTR_VAL(str));
|
docp->URL = xmlStrdup((const xmlChar *) ZSTR_VAL(str));
|
||||||
|
|
||||||
zend_string_release_ex(str, 0);
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -185,8 +185,8 @@ zend_result dom_node_node_value_write(dom_object *obj, zval *newval)
|
||||||
{
|
{
|
||||||
DOM_PROP_NODE(xmlNodePtr, nodep, obj);
|
DOM_PROP_NODE(xmlNodePtr, nodep, obj);
|
||||||
|
|
||||||
/* Cannot fail because the type is either null or a string. */
|
/* Type is ?string */
|
||||||
zend_string *str = zval_get_string(newval);
|
zend_string *str = Z_TYPE_P(newval) == IS_NULL ? ZSTR_EMPTY_ALLOC() : Z_STR_P(newval);
|
||||||
|
|
||||||
/* Access to Element node is implemented as a convenience method */
|
/* Access to Element node is implemented as a convenience method */
|
||||||
switch (nodep->type) {
|
switch (nodep->type) {
|
||||||
|
@ -213,7 +213,6 @@ zend_result dom_node_node_value_write(dom_object *obj, zval *newval)
|
||||||
|
|
||||||
php_libxml_invalidate_node_list_cache(obj->document);
|
php_libxml_invalidate_node_list_cache(obj->document);
|
||||||
|
|
||||||
zend_string_release_ex(str, 0);
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -206,13 +206,14 @@ static zend_result php_dom_xpath_callback_ns_update_method_handler(
|
||||||
ZVAL_PTR(®istered_value, fcc);
|
ZVAL_PTR(®istered_value, fcc);
|
||||||
|
|
||||||
if (!key) {
|
if (!key) {
|
||||||
zend_string *str = zval_try_get_string(entry);
|
zend_string *tmp_str;
|
||||||
|
zend_string *str = zval_try_get_tmp_string(entry, &tmp_str);
|
||||||
if (str && php_dom_xpath_is_callback_name_valid_and_throw(str, name_validation, true)) {
|
if (str && php_dom_xpath_is_callback_name_valid_and_throw(str, name_validation, true)) {
|
||||||
zend_hash_update(&ns->functions, str, ®istered_value);
|
zend_hash_update(&ns->functions, str, ®istered_value);
|
||||||
if (register_func) {
|
if (register_func) {
|
||||||
register_func(ctxt, namespace, str);
|
register_func(ctxt, namespace, str);
|
||||||
}
|
}
|
||||||
zend_string_release_ex(str, false);
|
zend_tmp_string_release(tmp_str);
|
||||||
} else {
|
} else {
|
||||||
zend_fcc_dtor(fcc);
|
zend_fcc_dtor(fcc);
|
||||||
efree(fcc);
|
efree(fcc);
|
||||||
|
@ -445,9 +446,10 @@ static zend_result php_dom_xpath_callback_dispatch(php_dom_xpath_callbacks *xpat
|
||||||
zval_ptr_dtor(&callback_retval);
|
zval_ptr_dtor(&callback_retval);
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
} else {
|
} else {
|
||||||
zend_string *str = zval_get_string(&callback_retval);
|
zend_string *tmp_str;
|
||||||
|
zend_string *str = zval_get_tmp_string(&callback_retval, &tmp_str);
|
||||||
valuePush(ctxt, xmlXPathNewString(BAD_CAST ZSTR_VAL(str)));
|
valuePush(ctxt, xmlXPathNewString(BAD_CAST ZSTR_VAL(str)));
|
||||||
zend_string_release_ex(str, 0);
|
zend_tmp_string_release(tmp_str);
|
||||||
}
|
}
|
||||||
zval_ptr_dtor(&callback_retval);
|
zval_ptr_dtor(&callback_retval);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue