1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-25 04:24:48 +03:00

Keep hash stored in StringData

This commit is contained in:
Maxime Coste 2015-05-14 19:13:52 +01:00
parent e9af3a4217
commit 802d6e106c
2 changed files with 9 additions and 7 deletions

View File

@ -180,7 +180,7 @@ void Buffer::reload(BufferLines lines, time_t fs_timestamp)
auto diff = find_diff(m_lines.begin(), m_lines.size(),
lines.begin(), (int)lines.size(),
[](const StringDataPtr& lhs, const StringDataPtr& rhs)
{ return lhs->strview() == rhs->strview(); });
{ return lhs->hash == rhs->hash and lhs->strview() == rhs->strview(); });
auto it = m_lines.begin();
for (auto& d : diff)

View File

@ -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: