summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-01-13 22:23:40 +0000
committerMaxime Coste <frrrwww@gmail.com>2014-01-13 22:23:40 +0000
commitab508ea3da188c669c11200c893a0348f67a1a0c (patch)
treeec56e57eeae4fb657a7534fb6cdd65b16eec14cc /src
parent86eaa64982a5aa450e703964773bde32b1d0d596 (diff)
Much faster implementation of SelectionList::merge_overlapping
Diffstat (limited to 'src')
-rw-r--r--src/selection.hh18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/selection.hh b/src/selection.hh
index aad74f95..66b348d1 100644
--- a/src/selection.hh
+++ b/src/selection.hh
@@ -120,18 +120,24 @@ struct SelectionList : std::vector<Selection>
void merge_overlapping(OverlapsFunc overlaps)
{
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]);
- erase(begin() + i + 1);
- if (i + 1 <= m_main)
+ (*this)[i].merge_with((*this)[j]);
+ if (i < m_main)
--m_main;
}
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()