mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:17:35 +00:00
AK: Make StringView::hash() constexpr
This required moving string_hash() to its own header so that everyone can see it.
This commit is contained in:
parent
9c38475608
commit
3e603b2f32
5 changed files with 36 additions and 25 deletions
|
@ -96,20 +96,6 @@ private:
|
|||
char m_inline_buffer[0];
|
||||
};
|
||||
|
||||
constexpr u32 string_hash(const char* characters, size_t length)
|
||||
{
|
||||
u32 hash = 0;
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
hash += (u32)characters[i];
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
}
|
||||
hash += hash << 3;
|
||||
hash ^= hash >> 11;
|
||||
hash += hash << 15;
|
||||
return hash;
|
||||
}
|
||||
|
||||
template<>
|
||||
struct Formatter<StringImpl> : Formatter<StringView> {
|
||||
void format(FormatBuilder& builder, const StringImpl& value)
|
||||
|
@ -122,5 +108,4 @@ struct Formatter<StringImpl> : Formatter<StringView> {
|
|||
|
||||
using AK::Chomp;
|
||||
using AK::NoChomp;
|
||||
using AK::string_hash;
|
||||
using AK::StringImpl;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue