refactor: Unify string hashing

> moved to util/utils.h
This commit is contained in:
[ ]
2025-12-15 23:53:18 +09:00
parent 42689377e6
commit 7f63b77ab3
4 changed files with 32 additions and 36 deletions
+12 -8
View File
@@ -2,6 +2,7 @@
#include "util/logging.h"
#include "util/detour.h"
#include "util/libutils.h"
#include "util/utils.h"
#include "avs/core.h"
#include "avs/game.h"
#include "hooks/wmischook.h"
@@ -76,10 +77,10 @@ void (*routine_cb_[devel_routine_last])() ={
[thum_test] = thumbnail::run
};
static constexpr unsigned int by_str(const char *str, int h = 0)
{
return !str[h] ? 5381 : (by_str(str, h + 1) * 33) ^ str[h];
}
//static constexpr unsigned int to_hash(const char *str, int h = 0)
//{
// return !str[h] ? 5381 : (to_hash(str, h + 1) * 33) ^ str[h];
//}
std::vector<std::string> from_env(const char *str)
{
std::vector<std::string> r;
@@ -101,17 +102,20 @@ static devel_routine_t routines()
routines_ = 0;
for (const auto &routine: from_env("SPICE_DEVEL"))
{
switch (by_str(routine.c_str()))
switch (to_hash(routine.c_str()))
{
case by_str("avs_fs_detour"):
case to_hash("avs_fs_detour"):
routines_ |= 1 << avs_fs_detour;
break;
case by_str("sndb_test"):
case to_hash("sndb_test"):
routines_ |= 1 << sndb_test;
break;
case by_str("thum_test"):
case to_hash("thum_test"):
routines_ |= 1 << thum_test;
break;
case to_hash("acm_test"):
routines_ |= 1 << acm_test;
break;
default:
break;
}