Skip to content

Commit ab9e616

Browse files
committed
AK: Add String::hash()
1 parent 3954630 commit ab9e616

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

AK/String.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ class String {
181181
return *this;
182182
}
183183

184+
u32 hash() const
185+
{
186+
if (!m_impl)
187+
return 0;
188+
return m_impl->hash();
189+
}
190+
184191
ByteBuffer to_byte_buffer() const;
185192

186193
template<typename BufferType>
@@ -205,7 +212,10 @@ class String {
205212
}
206213
#endif
207214

208-
StringView view() const { return { characters(), length() }; }
215+
StringView view() const
216+
{
217+
return { characters(), length() };
218+
}
209219

210220
private:
211221
bool match_helper(const StringView& mask) const;
@@ -234,7 +244,6 @@ struct Traits<String> : public GenericTraits<String> {
234244
struct CaseInsensitiveStringTraits : public AK::Traits<String> {
235245
static unsigned hash(const String& s) { return s.impl() ? s.to_lowercase().impl()->hash() : 0; }
236246
static bool equals(const String& a, const String& b) { return a.to_lowercase() == b.to_lowercase(); }
237-
238247
};
239248

240249
inline bool operator<(const char* characters, const String& string)
@@ -271,5 +280,5 @@ inline bool operator<=(const char* characters, const String& string)
271280

272281
}
273282

274-
using AK::String;
275283
using AK::CaseInsensitiveStringTraits;
284+
using AK::String;

0 commit comments

Comments
 (0)