minor performance tweaks

This commit is contained in:
Maxime Coste 2013-02-27 19:03:33 +01:00
parent cd8c36fc50
commit be0c5ddf49
2 changed files with 15 additions and 8 deletions

View File

@ -76,7 +76,7 @@ inline void BufferIterator::on_insert(const BufferCoord& begin,
if (m_coord < begin) if (m_coord < begin)
return; return;
if (begin.line == line()) if (begin.line == m_coord.line)
m_coord.column = end.column + m_coord.column - begin.column; m_coord.column = end.column + m_coord.column - begin.column;
m_coord.line += end.line - begin.line; m_coord.line += end.line - begin.line;
@ -90,7 +90,11 @@ inline void BufferIterator::on_erase(const BufferCoord& begin,
return; return;
if (m_coord <= end) if (m_coord <= end)
{
m_coord = begin; m_coord = begin;
if (is_end())
operator--();
}
else else
{ {
if (end.line == m_coord.line) if (end.line == m_coord.line)
@ -101,9 +105,6 @@ inline void BufferIterator::on_erase(const BufferCoord& begin,
else else
m_coord.line -= end.line - begin.line; m_coord.line -= end.line - begin.line;
} }
if (is_end())
operator--();
assert(is_valid()); assert(is_valid());
} }

View File

@ -63,28 +63,34 @@ DynamicSelectionList& DynamicSelectionList::operator=(SelectionList selections)
void DynamicSelectionList::check_invariant() const void DynamicSelectionList::check_invariant() const
{ {
#ifdef KAK_DEBUG
for (auto& sel : *this) for (auto& sel : *this)
{ {
assert(m_buffer == &sel.buffer()); assert(m_buffer == &sel.buffer());
sel.check_invariant(); sel.check_invariant();
} }
#endif
} }
void DynamicSelectionList::on_insert(const BufferIterator& begin, const BufferIterator& end) void DynamicSelectionList::on_insert(const BufferIterator& begin, const BufferIterator& end)
{ {
const BufferCoord begin_coord{begin.coord()};
const BufferCoord end_coord{end.coord()};
for (auto& sel : *this) for (auto& sel : *this)
{ {
sel.first().on_insert(begin.coord(), end.coord()); sel.first().on_insert(begin_coord, end_coord);
sel.last().on_insert(begin.coord(), end.coord()); sel.last().on_insert(begin_coord, end_coord);
} }
} }
void DynamicSelectionList::on_erase(const BufferIterator& begin, const BufferIterator& end) void DynamicSelectionList::on_erase(const BufferIterator& begin, const BufferIterator& end)
{ {
const BufferCoord begin_coord{begin.coord()};
const BufferCoord end_coord{end.coord()};
for (auto& sel : *this) for (auto& sel : *this)
{ {
sel.first().on_erase(begin.coord(), end.coord()); sel.first().on_erase(begin_coord, end_coord);
sel.last().on_erase(begin.coord(), end.coord()); sel.last().on_erase(begin_coord, end_coord);
} }
} }