summaryrefslogtreecommitdiff
path: root/src/buffer.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2019-11-30 10:46:42 +1100
committerMaxime Coste <mawww@kakoune.org>2019-11-30 11:29:36 +1100
commit4fdbf21ff8b042d48c9fb8a506bdc63018631453 (patch)
treec0414da81b2e87dba004e34eab9c6952f04d1452 /src/buffer.cc
parentb765fb4971db28bac608abc5cd856a9cb94fcfe1 (diff)
Refactor diff to make allocating a diff vector optional
The diff interface now goes through a for_each_diff function that uses a callback for each found diff.
Diffstat (limited to 'src/buffer.cc')
-rw-r--r--src/buffer.cc17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/buffer.cc b/src/buffer.cc
index 90a4e9f2..fbf1c29d 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -262,17 +262,20 @@ void Buffer::reload(StringView data, timespec fs_timestamp)
}
else
{
- auto diff = find_diff(m_lines.begin(), m_lines.size(),
- parsed_lines.lines.begin(), parsed_lines.lines.size(),
- [](const StringDataPtr& lhs, const StringDataPtr& rhs)
- { return lhs->strview() == rhs->strview(); });
+ Vector<Diff> diff;
+ for_each_diff(m_lines.begin(), m_lines.size(),
+ parsed_lines.lines.begin(), parsed_lines.lines.size(),
+ [&diff](DiffOp op, int len, int posB)
+ { diff.push_back({op, len, posB}); },
+ [](const StringDataPtr& lhs, const StringDataPtr& rhs)
+ { return lhs->strview() == rhs->strview(); });
auto it = m_lines.begin();
for (auto& d : diff)
{
- if (d.mode == Diff::Keep)
+ if (d.op == DiffOp::Keep)
it += d.len;
- else if (d.mode == Diff::Add)
+ else if (d.op == DiffOp::Add)
{
const LineCount cur_line = (int)(it - m_lines.begin());
@@ -285,7 +288,7 @@ void Buffer::reload(StringView data, timespec fs_timestamp)
m_lines.insert(it, parsed_lines.lines.begin() + d.posB, parsed_lines.lines.begin() + d.posB + d.len);
it = m_lines.begin() + (int)(cur_line + d.len);
}
- else if (d.mode == Diff::Remove)
+ else if (d.op == DiffOp::Remove)
{
const LineCount cur_line = (int)(it - m_lines.begin());