Slight code cleanup in change update functions

This commit is contained in:
Maxime Coste 2017-11-07 20:00:45 +08:00
parent d6b5240bdf
commit 80ce768994

View File

@ -32,11 +32,10 @@ template<typename RangeContainer>
void update_forward(ConstArrayView<Buffer::Change> changes, RangeContainer& ranges) void update_forward(ConstArrayView<Buffer::Change> changes, RangeContainer& ranges)
{ {
ForwardChangesTracker changes_tracker; ForwardChangesTracker changes_tracker;
auto advance_while_relevant = [&, it = changes.begin()]
auto change_it = changes.begin(); (const BufferCoord& pos) mutable {
auto advance_while_relevant = [&](const BufferCoord& pos) mutable { while (it != changes.end() and changes_tracker.relevant(*it, pos))
while (change_it != changes.end() and changes_tracker.relevant(*change_it, pos)) changes_tracker.update(*it++);
changes_tracker.update(*change_it++);
}; };
for (auto& range : ranges) for (auto& range : ranges)
@ -55,14 +54,13 @@ template<typename RangeContainer>
void update_backward(ConstArrayView<Buffer::Change> changes, RangeContainer& ranges) void update_backward(ConstArrayView<Buffer::Change> changes, RangeContainer& ranges)
{ {
ForwardChangesTracker changes_tracker; ForwardChangesTracker changes_tracker;
auto advance_while_relevant = [&, it = changes.rbegin()]
auto advance_while_relevant = [&, it = changes.rbegin(), end = changes.rend()]
(const BufferCoord& pos) mutable { (const BufferCoord& pos) mutable {
while (it != end) while (it != changes.rend())
{ {
auto change = *it; const Buffer::Change change{it->type,
change.begin = changes_tracker.get_new_coord(change.begin); changes_tracker.get_new_coord(it->begin),
change.end = changes_tracker.get_new_coord(change.end); changes_tracker.get_new_coord(it->end)};
if (not changes_tracker.relevant(change, pos)) if (not changes_tracker.relevant(change, pos))
break; break;
changes_tracker.update(change); changes_tracker.update(change);