diff options
| author | Maxime Coste <mawww@kakoune.org> | 2023-06-09 16:38:14 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2023-06-09 16:38:14 +1000 |
| commit | e0728d3434d5ea335521484521d246473ca06165 (patch) | |
| tree | cf343c50b25f2fc62bcceeba96ace5ac17fccf80 /src/display_buffer.hh | |
| parent | 5a31d331b979f865e1ab1a637bcde9451866ff9f (diff) | |
Speed up regions highlighting on files with big lines
Range atoms should always appear in order, so we can iterate a single
time through the display lines and display atoms while applying
hightlighters to regions
Diffstat (limited to 'src/display_buffer.hh')
| -rw-r--r-- | src/display_buffer.hh | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/display_buffer.hh b/src/display_buffer.hh index c81fc2f6..e3b4983e 100644 --- a/src/display_buffer.hh +++ b/src/display_buffer.hh @@ -135,13 +135,19 @@ public: iterator insert(iterator it, DisplayAtom atom); template<typename It> - iterator insert(iterator it, It beg, It end) + iterator insert(iterator pos, It beg, It end) { - auto res = m_atoms.insert(it, beg, end); - compute_range(); - return res; + auto has_buffer_range = std::mem_fn(&DisplayAtom::has_buffer_range); + if (auto first = std::find_if(beg, end, has_buffer_range); first != end) + { + auto last = std::find_if(std::reverse_iterator(end), std::reverse_iterator(first), has_buffer_range); + m_range.begin = std::min(m_range.begin, first->begin()); + m_range.end = std::max(m_range.end, last->end()); + } + return m_atoms.insert(pos, beg, end); } + DisplayLine extract(iterator beg, iterator end); iterator erase(iterator beg, iterator end); DisplayAtom& push_back(DisplayAtom atom); |
