Buffer::on_erase: avoid resizing lines more than necessary

This commit is contained in:
Maxime Coste 2013-03-15 14:15:29 +01:00
parent 5dc6a36bf8
commit 84e3c99c93

View File

@ -326,9 +326,13 @@ void Buffer::do_erase(const BufferIterator& begin, const BufferIterator& end)
String suffix = m_lines[end.line()].content.substr(end.column());
Line new_line = { m_lines[begin.line()].start, prefix + suffix };
m_lines.erase(m_lines.begin() + (int)begin.line(), m_lines.begin() + (int)end.line() + 1);
if (new_line.length() != 0)
m_lines.insert(m_lines.begin() + (int)begin.line(), std::move(new_line));
{
m_lines.erase(m_lines.begin() + (int)begin.line(), m_lines.begin() + (int)end.line());
m_lines[begin.line()] = std::move(new_line);
}
else
m_lines.erase(m_lines.begin() + (int)begin.line(), m_lines.begin() + (int)end.line() + 1);
for (LineCount i = begin.line()+1; i < line_count(); ++i)
m_lines[i].start -= length;