mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Add dedicated Traits for c-strings
This commit is contained in:
parent
dea86f511c
commit
6c6e917cf0
Notes:
sideshowbarker
2024-07-17 22:46:53 +09:00
Author: https://github.com/Hendiadyoin1 Commit: https://github.com/SerenityOS/serenity/commit/6c6e917cf04 Pull-request: https://github.com/SerenityOS/serenity/pull/10808 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/linusg Reviewed-by: https://github.com/trflynn89 ✅
1 changed files with 10 additions and 1 deletions
11
AK/Traits.h
11
AK/Traits.h
|
@ -9,6 +9,8 @@
|
||||||
#include <AK/Concepts.h>
|
#include <AK/Concepts.h>
|
||||||
#include <AK/Forward.h>
|
#include <AK/Forward.h>
|
||||||
#include <AK/HashFunctions.h>
|
#include <AK/HashFunctions.h>
|
||||||
|
#include <AK/StringHash.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
|
@ -37,7 +39,7 @@ requires(IsIntegral<T>) struct Traits<T> : public GenericTraits<T> {
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
requires(IsPointer<T>) struct Traits<T> : public GenericTraits<T> {
|
requires(IsPointer<T> && !Detail::IsPointerOfType<char, T>) struct Traits<T> : public GenericTraits<T> {
|
||||||
static unsigned hash(T p) { return ptr_hash((FlatPtr)p); }
|
static unsigned hash(T p) { return ptr_hash((FlatPtr)p); }
|
||||||
static constexpr bool is_trivial() { return true; }
|
static constexpr bool is_trivial() { return true; }
|
||||||
};
|
};
|
||||||
|
@ -48,6 +50,13 @@ struct Traits<T> : public GenericTraits<T> {
|
||||||
static constexpr bool is_trivial() { return Traits<UnderlyingType<T>>::is_trivial(); }
|
static constexpr bool is_trivial() { return Traits<UnderlyingType<T>>::is_trivial(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
requires(Detail::IsPointerOfType<char, T>) struct Traits<T> : public GenericTraits<T> {
|
||||||
|
static unsigned hash(T const value) { return string_hash(value, strlen(value)); }
|
||||||
|
static constexpr bool equals(T const a, T const b) { return strcmp(a, b); }
|
||||||
|
static constexpr bool is_trivial() { return true; }
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using AK::GenericTraits;
|
using AK::GenericTraits;
|
||||||
|
|
Loading…
Reference in a new issue