Faster BufferIterator::operator++/--

This commit is contained in:
Maxime Coste 2015-11-12 13:59:36 +00:00
parent 2113b829df
commit 67d1b7dcd1
2 changed files with 6 additions and 13 deletions

View File

@ -58,7 +58,7 @@ private:
SafePtr<const Buffer> m_buffer;
ByteCoord m_coord;
ByteCount m_line_length;
LineCount m_line_count;
LineCount m_last_line;
};
using BufferLines = Vector<StringDataPtr, MemoryDomain::BufferContent>;

View File

@ -108,7 +108,7 @@ inline ByteCoord Buffer::end_coord() const
inline BufferIterator::BufferIterator(const Buffer& buffer, ByteCoord coord)
: m_buffer(&buffer), m_coord(coord),
m_line_length((*m_buffer)[m_coord.line].length()),
m_line_count(buffer.line_count())
m_last_line(buffer.line_count()-1)
{
kak_assert(m_buffer and m_buffer->is_valid(m_coord));
}
@ -193,11 +193,7 @@ inline BufferIterator& BufferIterator::operator-=(ByteCount size)
inline BufferIterator& BufferIterator::operator++()
{
if (m_coord.column < m_line_length - 1)
++m_coord.column;
else if (m_coord.line == m_line_count - 1)
m_coord.column = m_line_length;
else
if (++m_coord.column == m_line_length and m_coord.line != m_last_line)
{
++m_coord.line;
m_coord.column = 0;
@ -208,13 +204,10 @@ inline BufferIterator& BufferIterator::operator++()
inline BufferIterator& BufferIterator::operator--()
{
if (m_coord.column == 0)
if (m_coord.column == 0 and m_coord.line > 0)
{
if (m_coord.line > 0)
{
m_line_length = m_buffer->line_storage(--m_coord.line)->length;
m_coord.column = m_line_length - 1;
}
m_line_length = m_buffer->line_storage(--m_coord.line)->length;
m_coord.column = m_line_length - 1;
}
else
--m_coord.column;