From 80ce768994c75952b75cf31bef3c67871e5e5723 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 7 Nov 2017 20:00:45 +0800 Subject: [PATCH] Slight code cleanup in change update functions --- src/changes.hh | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/changes.hh b/src/changes.hh index c89ea529..ffae651a 100644 --- a/src/changes.hh +++ b/src/changes.hh @@ -32,11 +32,10 @@ template void update_forward(ConstArrayView changes, RangeContainer& ranges) { ForwardChangesTracker changes_tracker; - - auto change_it = changes.begin(); - auto advance_while_relevant = [&](const BufferCoord& pos) mutable { - while (change_it != changes.end() and changes_tracker.relevant(*change_it, pos)) - changes_tracker.update(*change_it++); + auto advance_while_relevant = [&, it = changes.begin()] + (const BufferCoord& pos) mutable { + while (it != changes.end() and changes_tracker.relevant(*it, pos)) + changes_tracker.update(*it++); }; for (auto& range : ranges) @@ -55,14 +54,13 @@ template void update_backward(ConstArrayView changes, RangeContainer& ranges) { ForwardChangesTracker changes_tracker; - - auto advance_while_relevant = [&, it = changes.rbegin(), end = changes.rend()] + auto advance_while_relevant = [&, it = changes.rbegin()] (const BufferCoord& pos) mutable { - while (it != end) + while (it != changes.rend()) { - auto change = *it; - change.begin = changes_tracker.get_new_coord(change.begin); - change.end = changes_tracker.get_new_coord(change.end); + const Buffer::Change change{it->type, + changes_tracker.get_new_coord(it->begin), + changes_tracker.get_new_coord(it->end)}; if (not changes_tracker.relevant(change, pos)) break; changes_tracker.update(change);