From 1b1196b28ad6c18f46e5797c19c4b02fcc2a19bc Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Wed, 18 Sep 2024 21:08:45 +0200 Subject: [PATCH] Small optimization in dom_local_name_compare_ex() 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%. --- ext/dom/serialize_common.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/dom/serialize_common.h b/ext/dom/serialize_common.h index 35203592da9ce..ed967c98a9eea 100644 --- a/ext/dom/serialize_common.h +++ b/ext/dom/serialize_common.h @@ -20,9 +20,10 @@ #include #include +/* 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