From 34e1c2ddd50fa70ecce19556cb812d135e099c26 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 14 May 2014 19:22:42 +0100 Subject: [PATCH] Fix RegexColorizer cache handling --- src/highlighters.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/highlighters.cc b/src/highlighters.cc index d0858eed..a73ba9e4 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -196,8 +196,8 @@ private: struct Cache { Cache(const Buffer&){} - BufferRange m_range; - size_t m_timestamp = 0; + std::pair m_range; + size_t m_timestamp = 0; std::vector>> m_matches; }; BufferSideCache m_cache; @@ -209,18 +209,21 @@ private: { Cache& cache = m_cache.get(buffer); + LineCount first_line = range.first.line; + LineCount last_line = std::min(buffer.line_count()-1, range.second.line); + if (buffer.timestamp() == cache.m_timestamp and - range.first >= cache.m_range.first and - range.second <= cache.m_range.second) + first_line >= cache.m_range.first and + last_line <= cache.m_range.second) return cache; - cache.m_range.first = buffer.clamp({range.first.line - 10, 0}); - cache.m_range.second = buffer.next(buffer.clamp({range.second.line + 10, INT_MAX})); + cache.m_range.first = std::max(0_line, first_line - 10); + cache.m_range.second = std::min(buffer.line_count()-1, last_line+10); cache.m_timestamp = buffer.timestamp(); cache.m_matches.clear(); RegexIterator re_it{buffer.iterator_at(cache.m_range.first), - buffer.iterator_at(cache.m_range.second), m_regex}; + buffer.iterator_at(cache.m_range.second+1), m_regex}; RegexIterator re_end; for (; re_it != re_end; ++re_it) {