Skip to content

Commit

Permalink
Small optimization in dom_local_name_compare_ex()
Browse files Browse the repository at this point in the history
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%.
  • Loading branch information
nielsdos committed Sep 19, 2024
1 parent c9a4aba commit 1b1196b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ext/dom/serialize_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
#include <Zend/zend_types.h>
#include <libxml/tree.h>

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

#endif

0 comments on commit 1b1196b

Please sign in to comment.