mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Add StringView::hash()
This grabs the hash from the underlying StringImpl if there is one, otherwise it's computed on the fly.
This commit is contained in:
parent
bb32fd8bfa
commit
d38bd3935b
Notes:
sideshowbarker
2024-07-19 12:32:58 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/d38bd3935b4
2 changed files with 11 additions and 0 deletions
|
@ -109,4 +109,13 @@ unsigned StringView::to_uint(bool& ok) const
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned StringView::hash() const
|
||||||
|
{
|
||||||
|
if (is_empty())
|
||||||
|
return 0;
|
||||||
|
if (m_impl)
|
||||||
|
return m_impl->hash();
|
||||||
|
return string_hash(characters_without_null_termination(), length());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,8 @@ public:
|
||||||
int length() const { return m_length; }
|
int length() const { return m_length; }
|
||||||
char operator[](int index) const { return m_characters[index]; }
|
char operator[](int index) const { return m_characters[index]; }
|
||||||
|
|
||||||
|
unsigned hash() const;
|
||||||
|
|
||||||
StringView substring_view(int start, int length) const;
|
StringView substring_view(int start, int length) const;
|
||||||
Vector<StringView> split_view(char) const;
|
Vector<StringView> split_view(char) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue