1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-20 01:41:40 +03:00

Remove hash from StringData

Maintaining the hash value of strings is not worth it as we only
use it for buffer reload, but pay for it on any buffer modifications.
This commit is contained in:
Maxime Coste 2017-01-28 13:04:55 +00:00
parent 1048036d3c
commit 072064407a
2 changed files with 4 additions and 17 deletions

View File

@ -249,7 +249,7 @@ void Buffer::reload(StringView data, timespec fs_timestamp)
auto diff = find_diff(m_lines.begin(), m_lines.size(),
parsed_lines.lines.begin(), (int)parsed_lines.lines.size(),
[](const StringDataPtr& lhs, const StringDataPtr& rhs)
{ return lhs->hash == rhs->hash and lhs->strview() == rhs->strview(); });
{ return lhs->strview() == rhs->strview(); });
auto it = m_lines.begin();
for (auto& d : diff)
@ -476,7 +476,7 @@ BufferCoord Buffer::do_insert(BufferCoord pos, StringView content)
auto line_it = m_lines.begin() + (int)pos.line;
auto new_lines_it = new_lines.begin();
if (not append_lines)
if (not append_lines) // replace first line with new first line
*line_it++ = std::move(*new_lines_it++);
m_lines.insert(line_it,

View File

@ -13,7 +13,6 @@ struct StringData : UseMemoryDomain<MemoryDomain::SharedString>
{
int refcount;
int length;
uint32_t hash;
StringData(int ref, int len) : refcount(ref), length(len) {}
@ -26,8 +25,8 @@ struct StringData : UseMemoryDomain<MemoryDomain::SharedString>
struct PtrPolicy
{
static void inc_ref(StringData* r, void*) { ++r->refcount; }
static void dec_ref(StringData* r, void*) { if (--r->refcount == 0) delete r; }
static void inc_ref(StringData* r, void*) noexcept { ++r->refcount; }
static void dec_ref(StringData* r, void*) noexcept { if (--r->refcount == 0) destroy(r); }
static void ptr_moved(StringData*, void*, void*) noexcept {}
};
@ -40,7 +39,6 @@ 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, PtrPolicy>{res};
}
@ -48,17 +46,6 @@ struct StringData : UseMemoryDomain<MemoryDomain::SharedString>
{
StringData::operator delete(s, sizeof(StringData) + s->length + 1);
}
friend void inc_ref_count(StringData* s, void*)
{
++s->refcount;
}
friend void dec_ref_count(StringData* s, void*)
{
if (--s->refcount == 0)
StringData::destroy(s);
}
};
using StringDataPtr = RefPtr<StringData, StringData::PtrPolicy>;