Skip to content

Use a ROL for mangling the pointer key in namespace_compat.c #14331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions ext/dom/namespace_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,9 @@ PHP_DOM_EXPORT void php_dom_reconcile_attribute_namespace_after_insertion(xmlAtt
static zend_always_inline zend_long dom_mangle_pointer_for_key(void *ptr)
{
zend_ulong value = (zend_ulong) (uintptr_t) ptr;
/* Shift 3/4 for better hash distribution because the low 3/4 bits are always 0. */
#if SIZEOF_ZEND_LONG == 8
return value >> 4;
#else
return value >> 3;
#endif
/* Rotate 3/4 bits for better hash distribution because the low 3/4 bits are normally 0. */
const size_t rol_amount = (SIZEOF_ZEND_LONG == 8) ? 4 : 3;
return (value >> rol_amount) | (value << (sizeof(value) * 8 - rol_amount));
}

static zend_always_inline void php_dom_libxml_reconcile_modern_single_node(dom_libxml_reconcile_ctx *ctx, xmlNodePtr node)
Expand Down
Loading