summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-01-14 19:42:57 +0000
committerMaxime Coste <frrrwww@gmail.com>2014-01-14 19:42:57 +0000
commitc2f18e6e78114dd00fce09e09337525328349ca0 (patch)
treedc959058002d76140e0ce2b930c909a6c9dc369d /src
parentab508ea3da188c669c11200c893a0348f67a1a0c (diff)
Use inplace_merge for sorting matches in region highlighter
Diffstat (limited to 'src')
-rw-r--r--src/highlighters.cc33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/highlighters.cc b/src/highlighters.cc
index e7d67db4..8809dfb5 100644
--- a/src/highlighters.cc
+++ b/src/highlighters.cc
@@ -633,35 +633,35 @@ private:
{
const size_t buf_timestamp = buffer.timestamp();
// remove out of date matches and update line for others
- for (auto it = matches.begin(); it != matches.end();)
+ auto ins_pos = matches.begin();
+ for (auto it = ins_pos; it != matches.end(); ++it)
{
auto change_it = std::lower_bound(cache.changes.begin(), cache.changes.end(), it->line,
[](const LineChange& c, const LineCount& l)
{ return c.pos < l; });
+ bool erase = false;
if (change_it != cache.changes.begin())
{
it->line += (change_it-1)->num;
- if (it->line <= (change_it-1)->pos)
- {
- std::swap(*it, matches.back());
- matches.pop_back();
- continue;
- }
- }
- if (it->line >= buffer.line_count() or
- it->timestamp < buffer.line_timestamp(it->line))
- {
- std::swap(*it, matches.back());
- matches.pop_back();
+ erase = it->line <= (change_it-1)->pos;
}
- else
+ erase = erase or (it->line >= buffer.line_count() or
+ it->timestamp < buffer.line_timestamp(it->line));
+
+ if (not erase)
{
it->timestamp = buf_timestamp;
kak_assert(buffer.is_valid({it->line, it->begin}));
kak_assert(buffer.is_valid({it->line, it->end}));
- ++it;
+
+ if (ins_pos != it)
+ *ins_pos = std::move(*it);
+ ++ins_pos;
}
}
+ matches.erase(ins_pos, matches.end());
+ size_t pivot = matches.size();
+
// try to find new matches in each updated lines
for (auto line = 0_line, end = buffer.line_count(); line < end; ++line)
{
@@ -676,7 +676,8 @@ private:
}
}
}
- std::sort(matches.begin(), matches.end(), compare_matches_begin);
+ std::inplace_merge(matches.begin(), matches.begin() + pivot, matches.end(),
+ compare_matches_begin);
}
};