From 072064407a6699d1168b7ac8919fea3056501a77 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 28 Jan 2017 13:04:55 +0000 Subject: [PATCH] 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. --- src/buffer.cc | 4 ++-- src/shared_string.hh | 17 ++--------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index 00506c7fa..275562629 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -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, diff --git a/src/shared_string.hh b/src/shared_string.hh index a13f042f3..a6522edb4 100644 --- a/src/shared_string.hh +++ b/src/shared_string.hh @@ -13,7 +13,6 @@ struct StringData : UseMemoryDomain { int refcount; int length; - uint32_t hash; StringData(int ref, int len) : refcount(ref), length(len) {} @@ -26,8 +25,8 @@ struct StringData : UseMemoryDomain 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 if (back != 0) res->data()[len-1] = back; res->data()[len] = 0; - res->hash = hash_data(res->data(), res->length); return RefPtr{res}; } @@ -48,17 +46,6 @@ struct StringData : UseMemoryDomain { 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;