Skip to content

Commit 08ba240

Browse files
authored
simplexml: Avoid double lookups and unnecessary allocations in getNamespaces() (#20447)
1 parent 4227106 commit 08ba240

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

ext/simplexml/simplexml.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,14 +1413,10 @@ PHP_METHOD(SimpleXMLElement, asXML)
14131413

14141414
static inline void sxe_add_namespace_name_raw(zval *return_value, const char *prefix, const char *href)
14151415
{
1416-
zend_string *key = zend_string_init(prefix, strlen(prefix), 0);
1417-
zval zv;
1418-
1419-
if (!zend_hash_exists(Z_ARRVAL_P(return_value), key)) {
1420-
ZVAL_STRING(&zv, href);
1421-
zend_hash_add_new(Z_ARRVAL_P(return_value), key, &zv);
1416+
zval *zv = zend_hash_str_lookup(Z_ARRVAL_P(return_value), prefix, strlen(prefix));
1417+
if (Z_ISNULL_P(zv)) {
1418+
ZVAL_STRING(zv, href);
14221419
}
1423-
zend_string_release_ex(key, 0);
14241420
}
14251421

14261422
static inline void sxe_add_namespace_name(zval *return_value, xmlNsPtr ns) /* {{{ */

0 commit comments

Comments
 (0)