diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2015-05-14 19:13:52 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2015-05-14 19:13:52 +0100 |
| commit | 802d6e106cb6a58ea2b0d4d0c986614e1713f34c (patch) | |
| tree | 1c67d2519aec5f8ecc4d4a17a441e0d648d7d99f /src/shared_string.hh | |
| parent | e9af3a4217843974c1e9c89bb8ddcfee44216c9e (diff) | |
Keep hash stored in StringData
Diffstat (limited to 'src/shared_string.hh')
| -rw-r--r-- | src/shared_string.hh | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/shared_string.hh b/src/shared_string.hh index 74232613..cc52e0d9 100644 --- a/src/shared_string.hh +++ b/src/shared_string.hh @@ -13,8 +13,9 @@ struct StringData : UseMemoryDomain<MemoryDomain::SharedString> { int refcount; int length; + uint32_t hash; - constexpr StringData(int ref, int len) : refcount(ref), length(len) {} + StringData(int ref, int len) : refcount(ref), length(len) {} [[gnu::always_inline]] char* data() { return reinterpret_cast<char*>(this + 1); } @@ -32,6 +33,7 @@ struct StringData : UseMemoryDomain<MemoryDomain::SharedString> if (back != 0) res->data()[len-1] = back; res->data()[len] = 0; + res->hash = hash_data(res->data(), res->length); return RefPtr<StringData>(res); } @@ -88,6 +90,11 @@ public: explicit SharedString(StringDataPtr storage) : StringView{storage->strview()}, m_storage(std::move(storage)) {} + friend size_t hash_value(const SharedString& str) + { + return str.m_storage ? str.m_storage->hash : hash_data(str.data(), (int)str.length()); + } + private: SharedString(StringView str, StringDataPtr storage) : StringView{str}, m_storage(std::move(storage)) {} @@ -96,11 +103,6 @@ private: StringDataPtr m_storage; }; -inline size_t hash_value(const SharedString& str) -{ - return hash_data(str.data(), (int)str.length()); -} - class StringRegistry : public Singleton<StringRegistry> { public: |
