From 9db76274b51f4a07a4a8b5c194811efc5032ddae Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Fri, 23 Feb 2024 13:28:22 +0200 Subject: [PATCH] hash for string_view --- loader/include/Geode/utils/general.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/loader/include/Geode/utils/general.hpp b/loader/include/Geode/utils/general.hpp index e95ffe4f..49354f6e 100644 --- a/loader/include/Geode/utils/general.hpp +++ b/loader/include/Geode/utils/general.hpp @@ -55,15 +55,19 @@ namespace geode { constexpr unsigned int hash(char const* str, int h = 0) { return !str[h] ? 5381 : (hash(str, h + 1) * 33) ^ str[h]; } - + constexpr unsigned int hash(std::string_view str, int h = 0) { + return h >= str.size() ? 5381 : (hash(str, h + 1) * 33) ^ str[h]; + } constexpr unsigned int hash(wchar_t const* str, int h = 0) { return !str[h] ? 5381 : (hash(str, h + 1) * 33) ^ str[h]; } + constexpr unsigned int hash(std::wstring_view str, int h = 0) { + return h >= str.size() ? 5381 : (hash(str, h + 1) * 33) ^ str[h]; + } constexpr size_t operator"" _h(char const* txt, size_t) { return geode::utils::hash(txt); } - constexpr size_t operator"" _h(wchar_t const* txt, size_t) { return geode::utils::hash(txt); }