type_info: internal changes

This commit is contained in:
Michele Caini 2024-10-22 19:19:17 +02:00
parent b53cd6fd8b
commit dd63b4e225

View File

@ -2,6 +2,7 @@
#define UVW_TYPE_INFO_INCLUDE_HPP #define UVW_TYPE_INFO_INCLUDE_HPP
#include <cstdint> #include <cstdint>
#include <string_view>
#include "config.h" #include "config.h"
namespace uvw { namespace uvw {
@ -14,14 +15,13 @@ namespace uvw {
namespace internal { namespace internal {
// Fowler-Noll-Vo hash function v. 1a - the good // Fowler-Noll-Vo hash function v. 1a - the good
[[nodiscard]] static constexpr std::uint32_t fnv1a(const char *curr) noexcept { [[nodiscard]] static constexpr std::uint32_t fnv1a(const std::string_view view) noexcept {
constexpr std::uint32_t offset = 2166136261; constexpr std::uint32_t offset = 2166136261;
constexpr std::uint32_t prime = 16777619; constexpr std::uint32_t prime = 16777619;
auto value = offset; auto value = offset;
while(*curr != 0) { for(auto &&curr: view) {
auto curr_val_int = static_cast<std::uint32_t>(*(curr++)); value = (value ^ static_cast<std::uint32_t>(curr)) * prime;
value = (value ^ curr_val_int) * prime;
} }
return value; return value;