Skip to content

Commit 7e6e712

Browse files
authored
Small optimization in dom_local_name_compare_ex() (#15950)
We can use `memcmp()` directly and skip some of the logic handling in `zend_binary_strcmp()`. `perf record` shows a reduction for `dom_html5_serializes_as_void()` from 3.12% to 0.77%.
1 parent 090b53b commit 7e6e712

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

ext/dom/serialize_common.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
#include <Zend/zend_types.h>
2121
#include <libxml/tree.h>
2222

23+
/* The lengths are merely here for optimization purposes, this cannot be used to compare substrings. */
2324
static zend_always_inline bool dom_local_name_compare_ex(const xmlNode *node, const char *tag, size_t tag_length, size_t name_length)
2425
{
25-
return name_length == tag_length && zend_binary_strcmp((const char *) node->name, name_length, tag, tag_length) == 0;
26+
return name_length == tag_length && memcmp((const char *) node->name, tag, name_length + 1) == 0;
2627
}
2728

2829
#endif

0 commit comments

Comments
 (0)