@@ -270,14 +270,16 @@ StringName::StringName(const char *p_name, bool p_static) {
270270 }
271271
272272 const uint32_t hash = String::hash (p_name);
273- const uint32_t idx = hash & STRING_TABLE_MASK;
273+ const uint32_t hash_mixed = hash_fmix32 (hash);
274+
275+ const uint32_t idx = hash_mixed & STRING_TABLE_MASK;
274276
275277 MutexLock lock (mutex);
276278 _data = _table[idx];
277279
278280 while (_data) {
279281 // compare hash first
280- if (_data->hash == hash && _data->operator ==(p_name)) {
282+ if (_data->hash_mixed == hash_mixed && _data->operator ==(p_name)) {
281283 break ;
282284 }
283285 _data = _data->next ;
@@ -305,6 +307,7 @@ StringName::StringName(const char *p_name, bool p_static) {
305307 _data->cname = nullptr ;
306308 _data->next = _table[idx];
307309 _data->prev = nullptr ;
310+ _data->hash_mixed = hash_mixed;
308311
309312#ifdef DEBUG_ENABLED
310313 if (unlikely (debug_stringname)) {
@@ -327,14 +330,16 @@ StringName::StringName(const StaticCString &p_static_string, bool p_static) {
327330 ERR_FAIL_COND (!p_static_string.ptr || !p_static_string.ptr [0 ]);
328331
329332 const uint32_t hash = String::hash (p_static_string.ptr );
330- const uint32_t idx = hash & STRING_TABLE_MASK;
333+ const uint32_t hash_mixed = hash_fmix32 (hash);
334+
335+ const uint32_t idx = hash_mixed & STRING_TABLE_MASK;
331336
332337 MutexLock lock (mutex);
333338 _data = _table[idx];
334339
335340 while (_data) {
336341 // compare hash first
337- if (_data->hash == hash && _data->operator ==(p_static_string.ptr )) {
342+ if (_data->hash_mixed == hash_mixed && _data->operator ==(p_static_string.ptr )) {
338343 break ;
339344 }
340345 _data = _data->next ;
@@ -362,6 +367,8 @@ StringName::StringName(const StaticCString &p_static_string, bool p_static) {
362367 _data->cname = p_static_string.ptr ;
363368 _data->next = _table[idx];
364369 _data->prev = nullptr ;
370+
371+ _data->hash_mixed = hash_mixed;
365372#ifdef DEBUG_ENABLED
366373 if (unlikely (debug_stringname)) {
367374 // Keep in memory, force static.
@@ -385,13 +392,14 @@ StringName::StringName(const String &p_name, bool p_static) {
385392 }
386393
387394 const uint32_t hash = p_name.hash ();
388- const uint32_t idx = hash & STRING_TABLE_MASK;
395+ const uint32_t hash_mixed = hash_fmix32 (hash);
396+ const uint32_t idx = hash_mixed & STRING_TABLE_MASK;
389397
390398 MutexLock lock (mutex);
391399 _data = _table[idx];
392400
393401 while (_data) {
394- if (_data->hash == hash && _data->operator ==(p_name)) {
402+ if (_data->hash_mixed == hash_mixed && _data->operator ==(p_name)) {
395403 break ;
396404 }
397405 _data = _data->next ;
@@ -419,6 +427,7 @@ StringName::StringName(const String &p_name, bool p_static) {
419427 _data->cname = nullptr ;
420428 _data->next = _table[idx];
421429 _data->prev = nullptr ;
430+ _data->hash_mixed = hash_mixed;
422431#ifdef DEBUG_ENABLED
423432 if (unlikely (debug_stringname)) {
424433 // Keep in memory, force static.
@@ -441,10 +450,11 @@ StringName StringName::search(const char *p_name) {
441450 return StringName ();
442451 }
443452
444- const uint32_t hash = String::hash (p_name);
453+ const uint32_t hash = hash_fmix32 ( String::hash (p_name) );
445454 const uint32_t idx = hash & STRING_TABLE_MASK;
446455
447456 MutexLock lock (mutex);
457+
448458 _Data *_data = _table[idx];
449459
450460 while (_data) {
@@ -476,10 +486,11 @@ StringName StringName::search(const char32_t *p_name) {
476486 return StringName ();
477487 }
478488
479- const uint32_t hash = String::hash (p_name);
489+ const uint32_t hash = hash_fmix32 ( String::hash (p_name) );
480490 const uint32_t idx = hash & STRING_TABLE_MASK;
481491
482492 MutexLock lock (mutex);
493+
483494 _Data *_data = _table[idx];
484495
485496 while (_data) {
@@ -500,10 +511,11 @@ StringName StringName::search(const char32_t *p_name) {
500511StringName StringName::search (const String &p_name) {
501512 ERR_FAIL_COND_V (p_name.is_empty (), StringName ());
502513
503- const uint32_t hash = p_name.hash ();
514+ const uint32_t hash = hash_fmix32 ( p_name.hash () );
504515 const uint32_t idx = hash & STRING_TABLE_MASK;
505516
506517 MutexLock lock (mutex);
518+
507519 _Data *_data = _table[idx];
508520
509521 while (_data) {
0 commit comments