From 84e3c99c9366bd015359aec426795313bde802b1 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 15 Mar 2013 14:15:29 +0100 Subject: [PATCH] Buffer::on_erase: avoid resizing lines more than necessary --- src/buffer.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index e86df929..1083d20b 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -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;