Much faster implementation of SelectionList::merge_overlapping

This commit is contained in:
Maxime Coste 2014-01-13 22:23:40 +00:00
parent 86eaa64982
commit ab508ea3da

View File

@ -120,19 +120,25 @@ struct SelectionList : std::vector<Selection>
void merge_overlapping(OverlapsFunc overlaps) void merge_overlapping(OverlapsFunc overlaps)
{ {
kak_assert(std::is_sorted(begin(), end(), compare_selections)); kak_assert(std::is_sorted(begin(), end(), compare_selections));
for (size_t i = 0; i+1 < size() and size() > 1;) size_t i = 0;
for (size_t j = 1; j < size(); ++j)
{ {
if (overlaps((*this)[i], (*this)[i+1])) if (overlaps((*this)[i], (*this)[j]))
{ {
(*this)[i].merge_with((*this)[i+1]); (*this)[i].merge_with((*this)[j]);
erase(begin() + i + 1); if (i < m_main)
if (i + 1 <= m_main)
--m_main; --m_main;
} }
else else
{
++i; ++i;
if (i != j)
(*this)[i] = std::move((*this)[j]);
} }
} }
erase(begin() + i + 1, end());
kak_assert(std::is_sorted(begin(), end(), compare_selections));
}
void sort_and_merge_overlapping() void sort_and_merge_overlapping()
{ {