dont intern SharedStrings but StringDataPtr
This commit is contained in:
parent
a8eddd03f0
commit
ff6eacffa3
|
@ -199,9 +199,9 @@ struct Buffer::Modification
|
||||||
|
|
||||||
Type type;
|
Type type;
|
||||||
ByteCoord coord;
|
ByteCoord coord;
|
||||||
SharedString content;
|
StringDataPtr content;
|
||||||
|
|
||||||
Modification(Type type, ByteCoord coord, SharedString content)
|
Modification(Type type, ByteCoord coord, StringDataPtr content)
|
||||||
: type(type), coord(coord), content(std::move(content)) {}
|
: type(type), coord(coord), content(std::move(content)) {}
|
||||||
|
|
||||||
Modification inverse() const
|
Modification inverse() const
|
||||||
|
@ -248,7 +248,7 @@ void Buffer::reload(StringView data, timespec fs_timestamp)
|
||||||
for (LineCount line = 0; line < d.len; ++line)
|
for (LineCount line = 0; line < d.len; ++line)
|
||||||
m_current_undo_group.emplace_back(
|
m_current_undo_group.emplace_back(
|
||||||
Modification::Insert, cur_line + line,
|
Modification::Insert, cur_line + line,
|
||||||
SharedString{parsed_lines.lines[(int)(d.posB + line)]});
|
parsed_lines.lines[(int)(d.posB + line)]);
|
||||||
|
|
||||||
m_changes.push_back({ Change::Insert, it == m_lines.end(), cur_line, cur_line + d.len });
|
m_changes.push_back({ Change::Insert, it == m_lines.end(), cur_line, cur_line + d.len });
|
||||||
m_lines.insert(it, &parsed_lines.lines[d.posB], &parsed_lines.lines[d.posB + d.len]);
|
m_lines.insert(it, &parsed_lines.lines[d.posB], &parsed_lines.lines[d.posB + d.len]);
|
||||||
|
@ -261,7 +261,7 @@ void Buffer::reload(StringView data, timespec fs_timestamp)
|
||||||
for (LineCount line = d.len-1; line >= 0; --line)
|
for (LineCount line = d.len-1; line >= 0; --line)
|
||||||
m_current_undo_group.emplace_back(
|
m_current_undo_group.emplace_back(
|
||||||
Modification::Erase, cur_line + line,
|
Modification::Erase, cur_line + line,
|
||||||
SharedString{m_lines.get_storage(cur_line + line)});
|
m_lines.get_storage(cur_line + line));
|
||||||
|
|
||||||
it = m_lines.erase(it, it + d.len);
|
it = m_lines.erase(it, it + d.len);
|
||||||
m_changes.push_back({ Change::Erase, it == m_lines.end(), cur_line, cur_line + d.len });
|
m_changes.push_back({ Change::Erase, it == m_lines.end(), cur_line, cur_line + d.len });
|
||||||
|
@ -433,7 +433,7 @@ ByteCoord Buffer::do_erase(ByteCoord begin, ByteCoord end)
|
||||||
|
|
||||||
void Buffer::apply_modification(const Modification& modification)
|
void Buffer::apply_modification(const Modification& modification)
|
||||||
{
|
{
|
||||||
StringView content = modification.content;
|
StringView content = modification.content->strview();
|
||||||
ByteCoord coord = modification.coord;
|
ByteCoord coord = modification.coord;
|
||||||
|
|
||||||
kak_assert(is_valid(coord));
|
kak_assert(is_valid(coord));
|
||||||
|
@ -467,7 +467,7 @@ BufferIterator Buffer::insert(const BufferIterator& pos, StringView content)
|
||||||
if (content.empty())
|
if (content.empty())
|
||||||
return pos;
|
return pos;
|
||||||
|
|
||||||
SharedString real_content;
|
StringDataPtr real_content;
|
||||||
if (pos == end() and content.back() != '\n')
|
if (pos == end() and content.back() != '\n')
|
||||||
real_content = intern(content + "\n");
|
real_content = intern(content + "\n");
|
||||||
else
|
else
|
||||||
|
@ -478,7 +478,7 @@ BufferIterator Buffer::insert(const BufferIterator& pos, StringView content)
|
||||||
auto coord = pos == end() ? ByteCoord{line_count()} : pos.coord();
|
auto coord = pos == end() ? ByteCoord{line_count()} : pos.coord();
|
||||||
if (not (m_flags & Flags::NoUndo))
|
if (not (m_flags & Flags::NoUndo))
|
||||||
m_current_undo_group.emplace_back(Modification::Insert, coord, real_content);
|
m_current_undo_group.emplace_back(Modification::Insert, coord, real_content);
|
||||||
return {*this, do_insert(pos.coord(), real_content)};
|
return {*this, do_insert(pos.coord(), real_content->strview())};
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferIterator Buffer::erase(BufferIterator begin, BufferIterator end)
|
BufferIterator Buffer::erase(BufferIterator begin, BufferIterator end)
|
||||||
|
|
|
@ -4,22 +4,22 @@
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
SharedString StringRegistry::intern(StringView str)
|
StringDataPtr StringRegistry::intern(StringView str)
|
||||||
{
|
{
|
||||||
auto it = m_strings.find({str, SharedString::NoCopy{}});
|
auto it = m_strings.find(str);
|
||||||
if (it == m_strings.end())
|
if (it == m_strings.end())
|
||||||
{
|
{
|
||||||
SharedString shared_str = str;
|
auto data = StringData::create(str);
|
||||||
it = m_strings.emplace(shared_str).first;
|
it = m_strings.emplace(data->strview(), data).first;
|
||||||
}
|
}
|
||||||
return *it;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringRegistry::purge_unused()
|
void StringRegistry::purge_unused()
|
||||||
{
|
{
|
||||||
for (auto it = m_strings.begin(); it != m_strings.end(); )
|
for (auto it = m_strings.begin(); it != m_strings.end(); )
|
||||||
{
|
{
|
||||||
if (it->m_storage->refcount == 1)
|
if (it->second->refcount == 1)
|
||||||
it = m_strings.erase(it);
|
it = m_strings.erase(it);
|
||||||
else
|
else
|
||||||
++it;
|
++it;
|
||||||
|
@ -34,8 +34,8 @@ void StringRegistry::debug_stats() const
|
||||||
size_t count = m_strings.size();
|
size_t count = m_strings.size();
|
||||||
for (auto& st : m_strings)
|
for (auto& st : m_strings)
|
||||||
{
|
{
|
||||||
total_refcount += st.m_storage->refcount - 1;
|
total_refcount += st.second->refcount - 1;
|
||||||
total_size += (int)st.m_storage->length;
|
total_size += (int)st.second->length;
|
||||||
}
|
}
|
||||||
write_to_debug_buffer(format(" data size: {}, mean: {}", total_size, (float)total_size/count));
|
write_to_debug_buffer(format(" data size: {}, mean: {}", total_size, (float)total_size/count));
|
||||||
write_to_debug_buffer(format(" refcounts: {}, mean: {}", total_refcount, (float)total_refcount/count));
|
write_to_debug_buffer(format(" refcounts: {}, mean: {}", total_refcount, (float)total_refcount/count));
|
||||||
|
|
|
@ -102,14 +102,14 @@ class StringRegistry : public Singleton<StringRegistry>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void debug_stats() const;
|
void debug_stats() const;
|
||||||
SharedString intern(StringView str);
|
StringDataPtr intern(StringView str);
|
||||||
void purge_unused();
|
void purge_unused();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UnorderedSet<SharedString, MemoryDomain::SharedString> m_strings;
|
UnorderedMap<StringView, StringDataPtr, MemoryDomain::SharedString> m_strings;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline SharedString intern(StringView str)
|
inline StringDataPtr intern(StringView str)
|
||||||
{
|
{
|
||||||
return StringRegistry::instance().intern(str);
|
return StringRegistry::instance().intern(str);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ void WordDB::add_words(const SharedString& line)
|
||||||
{
|
{
|
||||||
for (auto& w : get_words(line))
|
for (auto& w : get_words(line))
|
||||||
{
|
{
|
||||||
WordDB::WordInfo& info = m_words[intern(w)];
|
WordDB::WordInfo& info = m_words[SharedString{intern(w)}];
|
||||||
++info.refcount;
|
++info.refcount;
|
||||||
if (info.letters.none())
|
if (info.letters.none())
|
||||||
info.letters = used_letters(w);
|
info.letters = used_letters(w);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user