Store direct ref_ptr<StringStorage> for WordDB lines

Storing a SharedString is a waste, we want the whole line.
This commit is contained in:
Maxime Coste 2015-01-27 13:11:32 +00:00
parent fb98ff652d
commit cc699faa54
3 changed files with 8 additions and 12 deletions

View File

@ -126,8 +126,8 @@ public:
StringView operator[](LineCount line) const StringView operator[](LineCount line) const
{ return m_lines[line]; } { return m_lines[line]; }
SharedString shared_line(LineCount line) const ref_ptr<StringStorage> line_storage(LineCount line) const
{ return m_lines.get_shared(line); } { return m_lines.get_storage(line); }
// returns an iterator at given coordinates. clamp line_and_column // returns an iterator at given coordinates. clamp line_and_column
BufferIterator iterator_at(ByteCoord coord) const; BufferIterator iterator_at(ByteCoord coord) const;
@ -181,10 +181,6 @@ private:
const ref_ptr<StringStorage>& get_storage(LineCount line) const const ref_ptr<StringStorage>& get_storage(LineCount line) const
{ return BufferLines::operator[]((int)line); } { return BufferLines::operator[]((int)line); }
[[gnu::always_inline]]
SharedString get_shared(LineCount line) const
{ return SharedString{get_storage(line)}; }
[[gnu::always_inline]] [[gnu::always_inline]]
StringView operator[](LineCount line) const StringView operator[](LineCount line) const
{ return get_storage(line)->strview(); } { return get_storage(line)->strview(); }

View File

@ -80,8 +80,8 @@ WordDB::WordDB(const Buffer& buffer)
m_lines.reserve((int)buffer.line_count()); m_lines.reserve((int)buffer.line_count());
for (auto line = 0_line, end = buffer.line_count(); line < end; ++line) for (auto line = 0_line, end = buffer.line_count(); line < end; ++line)
{ {
m_lines.push_back(buffer[line]); m_lines.push_back(buffer.line_storage(line));
add_words(get_words(m_lines.back())); add_words(get_words(SharedString{m_lines.back()}));
} }
} }
@ -111,7 +111,7 @@ void WordDB::update_db()
while (old_line <= modif.old_line + modif.num_removed) while (old_line <= modif.old_line + modif.num_removed)
{ {
kak_assert(old_line < m_lines.size()); kak_assert(old_line < m_lines.size());
remove_words(get_words(m_lines[(int)old_line++])); remove_words(get_words(SharedString{m_lines[(int)old_line++]}));
} }
for (auto l = 0_line; l <= modif.num_added; ++l) for (auto l = 0_line; l <= modif.num_added; ++l)
@ -119,8 +119,8 @@ void WordDB::update_db()
if (modif.new_line + l >= buffer.line_count()) if (modif.new_line + l >= buffer.line_count())
break; break;
new_lines.push_back(buffer.shared_line(modif.new_line + l)); new_lines.push_back(buffer.line_storage(modif.new_line + l));
add_words(get_words(new_lines.back())); add_words(get_words(SharedString{new_lines.back()}));
} }
} }
while (old_line != (int)m_lines.size()) while (old_line != (int)m_lines.size())

View File

@ -50,7 +50,7 @@ private:
int refcount; int refcount;
}; };
using WordToInfo = UnorderedMap<SharedString, WordInfo, MemoryDomain::WordDB>; using WordToInfo = UnorderedMap<SharedString, WordInfo, MemoryDomain::WordDB>;
using Lines = Vector<SharedString, MemoryDomain::WordDB>; using Lines = Vector<ref_ptr<StringStorage>, MemoryDomain::WordDB>;
safe_ptr<const Buffer> m_buffer; safe_ptr<const Buffer> m_buffer;
size_t m_timestamp; size_t m_timestamp;