replace LineChangeWatcher with a free function compute_line_modifications
This commit is contained in:
parent
0ec0f7c320
commit
2f1388df7b
|
@ -5,7 +5,7 @@
|
||||||
#include "color_registry.hh"
|
#include "color_registry.hh"
|
||||||
#include "context.hh"
|
#include "context.hh"
|
||||||
#include "display_buffer.hh"
|
#include "display_buffer.hh"
|
||||||
#include "line_change_watcher.hh"
|
#include "line_modification.hh"
|
||||||
#include "option_types.hh"
|
#include "option_types.hh"
|
||||||
#include "register_manager.hh"
|
#include "register_manager.hh"
|
||||||
#include "string.hh"
|
#include "string.hh"
|
||||||
|
@ -158,7 +158,7 @@ struct BufferSideCache
|
||||||
{
|
{
|
||||||
Value& cache_val = buffer.values()[m_id];
|
Value& cache_val = buffer.values()[m_id];
|
||||||
if (not cache_val)
|
if (not cache_val)
|
||||||
cache_val = Value(T{buffer});
|
cache_val = Value(T{});
|
||||||
return cache_val.as<T>();
|
return cache_val.as<T>();
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
@ -195,7 +195,6 @@ public:
|
||||||
private:
|
private:
|
||||||
struct Cache
|
struct Cache
|
||||||
{
|
{
|
||||||
Cache(const Buffer&){}
|
|
||||||
BufferRange m_range;
|
BufferRange m_range;
|
||||||
size_t m_timestamp = 0;
|
size_t m_timestamp = 0;
|
||||||
std::vector<std::vector<std::pair<ByteCoord, ByteCoord>>> m_matches;
|
std::vector<std::vector<std::pair<ByteCoord, ByteCoord>>> m_matches;
|
||||||
|
@ -671,10 +670,8 @@ private:
|
||||||
: lhs.begin < rhs.begin;
|
: lhs.begin < rhs.begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Cache : public LineChangeWatcher
|
struct Cache
|
||||||
{
|
{
|
||||||
Cache(const Buffer& buffer) : LineChangeWatcher(buffer) {}
|
|
||||||
|
|
||||||
size_t timestamp = 0;
|
size_t timestamp = 0;
|
||||||
MatchList begin_matches;
|
MatchList begin_matches;
|
||||||
MatchList end_matches;
|
MatchList end_matches;
|
||||||
|
@ -696,7 +693,7 @@ private:
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto modifs = cache.compute_modifications();
|
auto modifs = compute_line_modifications(buffer, cache.timestamp);
|
||||||
update_matches(buffer, modifs, cache.begin_matches, m_begin);
|
update_matches(buffer, modifs, cache.begin_matches, m_begin);
|
||||||
update_matches(buffer, modifs, cache.end_matches, m_end);
|
update_matches(buffer, modifs, cache.end_matches, m_end);
|
||||||
}
|
}
|
||||||
|
@ -718,7 +715,7 @@ private:
|
||||||
beg_it = std::upper_bound(beg_it, cache.begin_matches.end(),
|
beg_it = std::upper_bound(beg_it, cache.begin_matches.end(),
|
||||||
*end_it, compare_matches_end);
|
*end_it, compare_matches_end);
|
||||||
}
|
}
|
||||||
cache.timestamp = buffer.timestamp();
|
cache.timestamp = buf_timestamp;
|
||||||
return cache.regions;
|
return cache.regions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "line_change_watcher.hh"
|
#include "line_modification.hh"
|
||||||
|
|
||||||
#include "buffer.hh"
|
#include "buffer.hh"
|
||||||
|
|
||||||
|
@ -42,13 +42,10 @@ struct LineChange
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LineChangeWatcher::LineChangeWatcher(const Buffer& buffer)
|
std::vector<LineModification> compute_line_modifications(const Buffer& buffer, size_t timestamp)
|
||||||
: m_buffer(&buffer), m_timestamp(buffer.timestamp()) {}
|
|
||||||
|
|
||||||
std::vector<LineModification> LineChangeWatcher::compute_modifications()
|
|
||||||
{
|
{
|
||||||
std::vector<LineModification> res;
|
std::vector<LineModification> res;
|
||||||
for (auto& buf_change : m_buffer->changes_since(m_timestamp))
|
for (auto& buf_change : buffer.changes_since(timestamp))
|
||||||
{
|
{
|
||||||
const LineChange change(buf_change);
|
const LineChange change(buf_change);
|
||||||
|
|
||||||
|
@ -102,7 +99,6 @@ std::vector<LineModification> LineChangeWatcher::compute_modifications()
|
||||||
it->new_line -= num_removed;
|
it->new_line -= num_removed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_timestamp = m_buffer->timestamp();
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,18 +19,7 @@ struct LineModification
|
||||||
LineCount diff() const { return new_line - old_line + num_added - num_removed; }
|
LineCount diff() const { return new_line - old_line + num_added - num_removed; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class LineChangeWatcher
|
std::vector<LineModification> compute_line_modifications(const Buffer& buffer, size_t timestamp);
|
||||||
{
|
|
||||||
public:
|
|
||||||
LineChangeWatcher (const Buffer& buffer);
|
|
||||||
|
|
||||||
std::vector<LineModification> compute_modifications();
|
|
||||||
|
|
||||||
const Buffer& buffer() const { return *m_buffer; }
|
|
||||||
private:
|
|
||||||
safe_ptr<const Buffer> m_buffer;
|
|
||||||
size_t m_timestamp;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "word_db.hh"
|
#include "word_db.hh"
|
||||||
|
|
||||||
#include "utils.hh"
|
#include "utils.hh"
|
||||||
|
#include "line_modification.hh"
|
||||||
#include "utf8_iterator.hh"
|
#include "utf8_iterator.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
|
@ -49,7 +50,7 @@ static void remove_words(WordDB::WordList& wl, const std::vector<String>& words)
|
||||||
}
|
}
|
||||||
|
|
||||||
WordDB::WordDB(const Buffer& buffer)
|
WordDB::WordDB(const Buffer& buffer)
|
||||||
: m_change_watcher{buffer}
|
: m_buffer{&buffer}, m_timestamp{buffer.timestamp()}
|
||||||
{
|
{
|
||||||
m_line_to_words.reserve((int)buffer.line_count());
|
m_line_to_words.reserve((int)buffer.line_count());
|
||||||
for (auto line = 0_line, end = buffer.line_count(); line < end; ++line)
|
for (auto line = 0_line, end = buffer.line_count(); line < end; ++line)
|
||||||
|
@ -61,11 +62,14 @@ WordDB::WordDB(const Buffer& buffer)
|
||||||
|
|
||||||
void WordDB::update_db()
|
void WordDB::update_db()
|
||||||
{
|
{
|
||||||
auto modifs = m_change_watcher.compute_modifications();
|
auto& buffer = *m_buffer;
|
||||||
|
|
||||||
|
auto modifs = compute_line_modifications(buffer, m_timestamp);
|
||||||
|
m_timestamp = buffer.timestamp();
|
||||||
|
|
||||||
if (modifs.empty())
|
if (modifs.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto& buffer = m_change_watcher.buffer();
|
|
||||||
|
|
||||||
LineToWords new_lines;
|
LineToWords new_lines;
|
||||||
new_lines.reserve((int)buffer.line_count());
|
new_lines.reserve((int)buffer.line_count());
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define word_db_hh_INCLUDED
|
#define word_db_hh_INCLUDED
|
||||||
|
|
||||||
#include "buffer.hh"
|
#include "buffer.hh"
|
||||||
#include "line_change_watcher.hh"
|
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
@ -26,7 +25,8 @@ private:
|
||||||
|
|
||||||
void update_db();
|
void update_db();
|
||||||
|
|
||||||
LineChangeWatcher m_change_watcher;
|
safe_ptr<const Buffer> m_buffer;
|
||||||
|
size_t m_timestamp;
|
||||||
WordList m_words;
|
WordList m_words;
|
||||||
LineToWords m_line_to_words;
|
LineToWords m_line_to_words;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user