From f2acc55b4279cafb8ee319c7dae17ad88519511a Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Sat, 20 Apr 2024 01:14:34 +0100 Subject: [PATCH] [*] Finally enable independent string allocators --- Include/auROXTL/auHashUtils.hpp | 57 ++++++++++++++++++++++++++++++- Include/auROXTL/auMemoryModel.hpp | 16 --------- Include/auROXTL/auResult.hpp | 1 - Include/auROXTL/auString.hpp | 3 +- Include/auROXTL/auStringUtils.hpp | 2 +- 5 files changed, 59 insertions(+), 20 deletions(-) diff --git a/Include/auROXTL/auHashUtils.hpp b/Include/auROXTL/auHashUtils.hpp index b51f5e9..cf49c8e 100644 --- a/Include/auROXTL/auHashUtils.hpp +++ b/Include/auROXTL/auHashUtils.hpp @@ -8,6 +8,7 @@ #pragma once #include "auFNV1Utils.hpp" +#include "auMemoryModel.hpp" #define _AU_HASH_UTILS_HAS_STD @@ -256,6 +257,17 @@ namespace AuHash return lhs == rhs; } }; + + template <> + struct equal, Aurora::Memory::StringAllocator>> + { + using is_transparent = void; + + bool operator()(std::string_view lhs, std::string_view rhs) const + { + return lhs == rhs; + } + }; } template )> @@ -322,6 +334,18 @@ namespace AuHash } }; + template <> + struct hash, Aurora::Memory::StringAllocator>> + { + using is_transparent = void; + using transparent_key_equal = equal, Aurora::Memory::StringAllocator>>; + + size_t operator()(std::string_view txt) const + { + return hash{}(txt); + } + }; + template <> struct less { @@ -337,6 +361,21 @@ namespace AuHash } }; + template <> + struct less, Aurora::Memory::StringAllocator>> + { + using is_transparent = void; + + bool operator()(std::string_view lhs, std::string_view rhs) const + { + #if 0 + return AuFnv1aRuntime(lhs.data(), lhs.size()) < AuFnv1aRuntime(rhs.data(), rhs.size()); + #else + return hash{}(lhs) < hash{}(rhs); + #endif + } + }; + template <> struct less { @@ -380,4 +419,20 @@ struct AuEnableHashCodeOnData #if defined(_AU_HASH_RETARD_COMPILER) #undef _AU_HASH_RETARD_COMPILER #undef _AH_HAS_RETARD_CONSTEXPR -#endif \ No newline at end of file +#endif + +namespace AuHash +{ + template + struct hash> + { + AuUInt operator ()(const AuSPtr &ptr) const + { + #if defined(AURORA_IS_32BIT) + return ComputeUnseededHash(AuUInt(ptr.get())); + #else + return ComputeLongHash(AuUInt(ptr.get())); + #endif + } + }; +} \ No newline at end of file diff --git a/Include/auROXTL/auMemoryModel.hpp b/Include/auROXTL/auMemoryModel.hpp index 4a1b9a3..87ccf33 100644 --- a/Include/auROXTL/auMemoryModel.hpp +++ b/Include/auROXTL/auMemoryModel.hpp @@ -309,20 +309,4 @@ namespace Aurora::Memory using StringAllocator = BaseAuroraRuntimeAllocator; #endif -} - -namespace AuHash -{ - template - struct hash> - { - AuUInt operator ()(const AuSPtr &ptr) const - { - #if defined(AURORA_IS_32BIT) - return ComputeUnseededHash(AuUInt(ptr.get())); - #else - return ComputeLongHash(AuUInt(ptr.get())); - #endif - } - }; } \ No newline at end of file diff --git a/Include/auROXTL/auResult.hpp b/Include/auROXTL/auResult.hpp index dbd4223..49f3578 100644 --- a/Include/auROXTL/auResult.hpp +++ b/Include/auROXTL/auResult.hpp @@ -8,7 +8,6 @@ #pragma once #include "auCopyMoveUtils.hpp" -#include "auHashUtils.hpp" template struct AuResult diff --git a/Include/auROXTL/auString.hpp b/Include/auROXTL/auString.hpp index 15b4a61..d9016fc 100644 --- a/Include/auROXTL/auString.hpp +++ b/Include/auROXTL/auString.hpp @@ -15,5 +15,6 @@ #elif defined(AURORA_ROXTL_STRING_USE_STR_ALLOCATOR) using AuString = std::basic_string, Aurora::Memory::StringAllocator>; #else - using AuString = std::string; + using AuString = std::basic_string, Aurora::Memory::StringAllocator>; + //using AuString = std::string; #endif diff --git a/Include/auROXTL/auStringUtils.hpp b/Include/auROXTL/auStringUtils.hpp index f3dd997..65a24fe 100644 --- a/Include/auROXTL/auStringUtils.hpp +++ b/Include/auROXTL/auStringUtils.hpp @@ -1047,7 +1047,7 @@ static auline AuString AuToString(const T &obj) { #if defined(_AUHAS_FMT) // locale independent and better optimized! - return fmt::format("{}", obj); + return AuString(fmt::format("{}", obj)); #else // TODO: to_chars (locale independent) return AURORA_RUNTIME_TO_STRING(obj);