From df90ba598470fe722ac6322fff43928f07782c59 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 11 Jun 2018 13:33:26 +1000 Subject: [PATCH] Extract update_ranges_ifn as a general utility function --- src/changes.hh | 26 ++++++++++++++++++++++++++ src/highlighters.cc | 31 +++---------------------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/changes.hh b/src/changes.hh index ffae651a..638a4bcb 100644 --- a/src/changes.hh +++ b/src/changes.hh @@ -80,6 +80,32 @@ void update_backward(ConstArrayView changes, RangeContainer& ran } } +template +void update_ranges(Buffer& buffer, size_t& timestamp, RangeContainer& ranges) +{ + if (timestamp == buffer.timestamp()) + return; + + auto changes = buffer.changes_since(timestamp); + for (auto change_it = changes.begin(); change_it != changes.end(); ) + { + auto forward_end = forward_sorted_until(change_it, changes.end()); + auto backward_end = backward_sorted_until(change_it, changes.end()); + + if (forward_end >= backward_end) + { + update_forward({ change_it, forward_end }, ranges); + change_it = forward_end; + } + else + { + update_backward({ change_it, backward_end }, ranges); + change_it = backward_end; + } + } + timestamp = buffer.timestamp(); +} + } #endif // changes_hh_INCLUDED diff --git a/src/highlighters.cc b/src/highlighters.cc index bd5ad191..3f9fbf46 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -1406,31 +1406,6 @@ InclusiveBufferRange option_from_string(Meta::Type, String BufferCoord& get_first(RangeAndString& r) { return std::get<0>(r).first; } BufferCoord& get_last(RangeAndString& r) { return std::get<0>(r).last; } -static void update_ranges_ifn(const Buffer& buffer, RangeAndStringList& range_and_faces) -{ - if (range_and_faces.prefix == buffer.timestamp()) - return; - - auto changes = buffer.changes_since(range_and_faces.prefix); - for (auto change_it = changes.begin(); change_it != changes.end(); ) - { - auto forward_end = forward_sorted_until(change_it, changes.end()); - auto backward_end = backward_sorted_until(change_it, changes.end()); - - if (forward_end >= backward_end) - { - update_forward({ change_it, forward_end }, range_and_faces.list); - change_it = forward_end; - } - else - { - update_backward({ change_it, backward_end }, range_and_faces.list); - change_it = backward_end; - } - } - range_and_faces.prefix = buffer.timestamp(); -} - void option_list_postprocess(Vector& opt) { std::sort(opt.begin(), opt.end(), @@ -1443,7 +1418,7 @@ void option_list_postprocess(Vector& opt) void option_update(RangeAndStringList& opt, const Context& context) { - update_ranges_ifn(context.buffer(), opt); + update_ranges(context.buffer(), opt.prefix, opt.list); } struct RangesHighlighter : Highlighter @@ -1469,7 +1444,7 @@ private: { auto& buffer = context.context.buffer(); auto& range_and_faces = context.context.options()[m_option_name].get_mutable(); - update_ranges_ifn(buffer, range_and_faces); + update_ranges(buffer, range_and_faces.prefix, range_and_faces.list); for (auto& range : range_and_faces.list) { @@ -1511,7 +1486,7 @@ private: { auto& buffer = context.context.buffer(); auto& range_and_faces = context.context.options()[m_option_name].get_mutable(); - update_ranges_ifn(buffer, range_and_faces); + update_ranges(buffer, range_and_faces.prefix, range_and_faces.list); for (auto& range : range_and_faces.list) {