Merge remote-tracking branch 'eraserhd/fifo-performance-fixes'

This commit is contained in:
Maxime Coste 2021-03-11 07:49:20 +11:00
commit 0b234f7f67
3 changed files with 26 additions and 8 deletions

View File

@ -53,8 +53,10 @@ void update_forward(ConstArrayView<Buffer::Change> changes, RangeContainer& rang
changes_tracker.update(*it++); changes_tracker.update(*it++);
}; };
for (auto& range : ranges) auto range_it = std::lower_bound(ranges.begin(), ranges.end(), changes.front(),
update_range(changes_tracker, range, advance_while_relevant); [](auto& range, const Buffer::Change& change) { return get_last(range) < change.begin; });
for (auto end = ranges.end(); range_it != end; ++range_it)
update_range(changes_tracker, *range_it, advance_while_relevant);
} }
template<typename RangeContainer> template<typename RangeContainer>

View File

@ -1523,14 +1523,16 @@ private:
BufferCoord& get_first(RangeAndString& r) { return std::get<0>(r).first; } BufferCoord& get_first(RangeAndString& r) { return std::get<0>(r).first; }
BufferCoord& get_last(RangeAndString& r) { return std::get<0>(r).last; } BufferCoord& get_last(RangeAndString& r) { return std::get<0>(r).last; }
bool option_element_compare(RangeAndString const& lhs, RangeAndString const& rhs)
{
return std::get<0>(lhs).first == std::get<0>(rhs).first ?
std::get<0>(lhs).last < std::get<0>(rhs).last
: std::get<0>(lhs).first < std::get<0>(rhs).first;
}
void option_list_postprocess(Vector<RangeAndString, MemoryDomain::Options>& opt) void option_list_postprocess(Vector<RangeAndString, MemoryDomain::Options>& opt)
{ {
std::sort(opt.begin(), opt.end(), std::sort(opt.begin(), opt.end(), option_element_compare);
[](auto& lhs, auto& rhs) {
return std::get<0>(lhs).first == std::get<0>(rhs).first ?
std::get<0>(lhs).last < std::get<0>(rhs).last
: std::get<0>(lhs).first < std::get<0>(rhs).first;
});
} }
void option_update(RangeAndStringList& opt, const Context& context) void option_update(RangeAndStringList& opt, const Context& context)
@ -1538,6 +1540,19 @@ void option_update(RangeAndStringList& opt, const Context& context)
update_ranges(context.buffer(), opt.prefix, opt.list); update_ranges(context.buffer(), opt.prefix, opt.list);
} }
bool option_add_from_strings(Vector<RangeAndString, MemoryDomain::Options>& opt, ConstArrayView<String> strs)
{
auto vec = option_from_strings(Meta::Type<Vector<RangeAndString, MemoryDomain::Options>>{}, strs);
if (vec.empty())
return false;
auto middle = opt.insert(opt.end(),
std::make_move_iterator(vec.begin()),
std::make_move_iterator(vec.end()));
std::sort(middle, opt.end(), option_element_compare);
std::inplace_merge(opt.begin(), middle, opt.end(), option_element_compare);
return true;
}
struct RangesHighlighter : OptionBasedHighlighter<RangeAndStringList, RangesHighlighter> struct RangesHighlighter : OptionBasedHighlighter<RangeAndStringList, RangesHighlighter>
{ {
using RangesHighlighter::OptionBasedHighlighter::OptionBasedHighlighter; using RangesHighlighter::OptionBasedHighlighter::OptionBasedHighlighter;

View File

@ -38,6 +38,7 @@ constexpr StringView option_type_name(Meta::Type<RangeAndStringList>)
} }
void option_update(RangeAndStringList& opt, const Context& context); void option_update(RangeAndStringList& opt, const Context& context);
void option_list_postprocess(Vector<RangeAndString, MemoryDomain::Options>& opt); void option_list_postprocess(Vector<RangeAndString, MemoryDomain::Options>& opt);
bool option_add_from_strings(Vector<RangeAndString, MemoryDomain::Options>& opt, ConstArrayView<String> strs);
} }