diff --git a/database_info.c b/database_info.c index 9059e03188..eaf5e4723f 100644 --- a/database_info.c +++ b/database_info.c @@ -31,17 +31,6 @@ #include -static INLINE uint32_t djb2(const char *str) -{ - const unsigned char *aux = (const unsigned char*)str; - uint32_t hash = 5381; - - while ( *aux ) - hash = ( hash << 5 ) + hash + *aux++; - - return hash; -} - #define DB_QUERY_ENTRY 0x1c310956U #define DB_QUERY_ENTRY_PUBLISHER 0x125e594dU #define DB_QUERY_ENTRY_DEVELOPER 0xcbd89be5U @@ -68,7 +57,7 @@ int database_info_build_query(char *s, size_t len, strlcpy(s, "{'", len); - value = djb2(label); + value = djb2_calculate(label); switch (value) { @@ -210,7 +199,7 @@ static int database_cursor_iterate(libretrodb_cursor_t *cur, if (!key || !val) continue; - value = djb2(key->string.buff); + value = djb2_calculate(key->string.buff); switch (value) { diff --git a/hash.c b/hash.c index ce9075895c..2f6922b985 100644 --- a/hash.c +++ b/hash.c @@ -522,3 +522,14 @@ error: close(fd); return -1; } + +uint32_t djb2_calculate(const char *str) +{ + const unsigned char *aux = (const unsigned char*)str; + uint32_t hash = 5381; + + while ( *aux ) + hash = ( hash << 5 ) + hash + *aux++; + + return hash; +} diff --git a/hash.h b/hash.h index a15219748c..4b9bc612cd 100644 --- a/hash.h +++ b/hash.h @@ -76,5 +76,7 @@ typedef struct SHA1Context int sha1_calculate(const char *path, char *result); +uint32_t djb2_calculate(const char *str); + #endif