Merge branch 'wip/smcv/64-bit-hash' into 'main'

ghash: Correctly retrieve low 32 bits of 64-bit values

Closes #2787

See merge request GNOME/glib!2994
This commit is contained in:
Philip Withnall 2022-10-24 20:22:15 +00:00
commit e33f23a6b5

View File

@ -2496,7 +2496,9 @@ g_int64_equal (gconstpointer v1,
guint guint
g_int64_hash (gconstpointer v) g_int64_hash (gconstpointer v)
{ {
return (guint) ((const guint) (*(guint64 *) v >> 32)) ^ (*(const guint *) v); const guint64 *bits = v;
return (guint) ((*bits >> 32) ^ (*bits & 0xffffffffU));
} }
/** /**
@ -2537,5 +2539,8 @@ g_double_equal (gconstpointer v1,
guint guint
g_double_hash (gconstpointer v) g_double_hash (gconstpointer v)
{ {
return (guint) ((const guint) (*(guint64 *) v >> 32)) ^ (*(const guint *) v); /* Same as g_int64_hash() */
const guint64 *bits = v;
return (guint) ((*bits >> 32) ^ (*bits & 0xffffffffU));
} }