From fc43d104dcd1c2336bad0c8cc0659832ddb744bc Mon Sep 17 00:00:00 2001 From: Max Wash Date: Wed, 1 Apr 2026 19:04:30 +0100 Subject: [PATCH] core: dict: fix fx_cstr_hash using different constants than other string hashing functions --- ds/dict.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ds/dict.c b/ds/dict.c index 47b12c3..37d1bed 100644 --- a/ds/dict.c +++ b/ds/dict.c @@ -5,9 +5,6 @@ #include #include -#define HASH_OFFSET_BASIS 0xcbf29ce484222325 -#define HASH_PRIME 0x100000001b3 - /*** PRIVATE DATA *************************************************************/ struct fx_dict_bucket_item { @@ -45,11 +42,14 @@ static FX_BST_DEFINE_SIMPLE_INSERT( uint64_t fx_cstr_hash(const char *s) { - uint64_t hash = HASH_OFFSET_BASIS; +#define FNV1_OFFSET_BASIS 0xcbf29ce484222325 +#define FNV1_PRIME 0x100000001b3 + uint64_t hash = FNV1_OFFSET_BASIS; + size_t i = 0; - for (size_t i = 0; s[i]; i++) { - hash *= HASH_PRIME; + for (i = 0; s[i]; i++) { hash ^= s[i]; + hash *= FNV1_PRIME; } return hash; @@ -448,8 +448,8 @@ static void dict_to_string(const fx_object *obj, fx_stream *out) fx_object_to_string(item->bi_str, out); fx_stream_write_string(out, ": ", NULL); - bool is_string - = fx_object_is_type(item->bi_value, FX_TYPE_STRING); + bool is_string = fx_object_is_type( + item->bi_value, FX_TYPE_STRING); if (is_string) { fx_stream_write_char(out, '"');