public: crclib: optimize COM_HashKey, implement typical djb hashing as this function is used for hashtables with string lookup

This commit is contained in:
Alibek Omarov 2023-03-13 02:37:19 +03:00
parent f9205825b6
commit 5c1e06ae74
1 changed files with 5 additions and 4 deletions

View File

@ -457,10 +457,11 @@ returns hash key for string
*/ */
uint COM_HashKey( const char *string, uint hashSize ) uint COM_HashKey( const char *string, uint hashSize )
{ {
uint i, hashKey = 0; int hashKey = 5381;
unsigned char i;
for( i = 0; string[i]; i++ ) while(( i = *string++ ))
hashKey = (hashKey + i) * 37 + Q_tolower( string[i] ); hashKey = ( hashKey << 5 ) + hashKey + ( i & 0xDF );
return (hashKey % hashSize); return hashKey & ( hashSize - 1 );
} }