Remove per lines timestamp in Buffer

This commit is contained in:
Maxime Coste 2014-05-17 12:17:05 +01:00
parent 079d34b82a
commit 03e5264df4
4 changed files with 12 additions and 18 deletions

View File

@ -35,7 +35,7 @@ Buffer::Buffer(String name, Flags flags, std::vector<String> lines,
for (auto& line : lines) for (auto& line : lines)
{ {
kak_assert(not line.empty() and line.back() == '\n'); kak_assert(not line.empty() and line.back() == '\n');
m_lines.emplace_back(Line{ m_changes.size()+1, pos, std::move(line) }); m_lines.emplace_back(Line{ pos, std::move(line) });
pos += m_lines.back().length(); pos += m_lines.back().length();
} }
@ -88,7 +88,7 @@ void Buffer::reload(std::vector<String> lines, time_t fs_timestamp)
for (auto& line : lines) for (auto& line : lines)
{ {
kak_assert(not line.empty() and line.back() == '\n'); kak_assert(not line.empty() and line.back() == '\n');
m_lines.emplace_back(Line{ m_changes.size()+1, pos, std::move(line) }); m_lines.emplace_back(Line{ pos, std::move(line) });
pos += m_lines.back().length(); pos += m_lines.back().length();
} }
m_fs_timestamp = fs_timestamp; m_fs_timestamp = fs_timestamp;
@ -460,12 +460,12 @@ ByteCoord Buffer::do_insert(ByteCoord pos, const String& content)
{ {
if (content[i] == '\n') if (content[i] == '\n')
{ {
m_lines.push_back({ m_changes.size()+1, offset + start, content.substr(start, i + 1 - start) }); m_lines.push_back({ offset + start, content.substr(start, i + 1 - start) });
start = i + 1; start = i + 1;
} }
} }
if (start != content.length()) if (start != content.length())
m_lines.push_back({ m_changes.size()+1, offset + start, content.substr(start) }); m_lines.push_back({ offset + start, content.substr(start) });
begin = pos.column == 0 ? pos : ByteCoord{ pos.line + 1, 0 }; begin = pos.column == 0 ? pos : ByteCoord{ pos.line + 1, 0 };
end = ByteCoord{ line_count()-1, m_lines.back().length() }; end = ByteCoord{ line_count()-1, m_lines.back().length() };
@ -487,18 +487,18 @@ ByteCoord Buffer::do_insert(ByteCoord pos, const String& content)
if (start == 0) if (start == 0)
{ {
line_content = prefix + line_content; line_content = prefix + line_content;
new_lines.push_back({ m_changes.size()+1, offset + start - prefix.length(), new_lines.push_back({ offset + start - prefix.length(),
std::move(line_content) }); std::move(line_content) });
} }
else else
new_lines.push_back({ m_changes.size()+1, offset + start, std::move(line_content) }); new_lines.push_back({ offset + start, std::move(line_content) });
start = i + 1; start = i + 1;
} }
} }
if (start == 0) if (start == 0)
new_lines.push_back({ m_changes.size()+1, offset + start - prefix.length(), prefix + content + suffix }); new_lines.push_back({ offset + start - prefix.length(), prefix + content + suffix });
else if (start != content.length() or not suffix.empty()) else if (start != content.length() or not suffix.empty())
new_lines.push_back({ m_changes.size()+1, offset + start, content.substr(start) + suffix }); new_lines.push_back({ offset + start, content.substr(start) + suffix });
LineCount last_line = pos.line + new_lines.size() - 1; LineCount last_line = pos.line + new_lines.size() - 1;
@ -523,7 +523,7 @@ ByteCoord Buffer::do_erase(ByteCoord begin, ByteCoord end)
const ByteCount length = distance(begin, end); const ByteCount length = distance(begin, end);
String prefix = m_lines[begin.line].content.substr(0, begin.column); String prefix = m_lines[begin.line].content.substr(0, begin.column);
String suffix = m_lines[end.line].content.substr(end.column); String suffix = m_lines[end.line].content.substr(end.column);
Line new_line = { m_changes.size()+1, m_lines[begin.line].start, prefix + suffix }; Line new_line = { m_lines[begin.line].start, prefix + suffix };
ByteCoord next; ByteCoord next;
if (new_line.length() != 0) if (new_line.length() != 0)

View File

@ -95,7 +95,6 @@ public:
BufferIterator erase(BufferIterator begin, BufferIterator end); BufferIterator erase(BufferIterator begin, BufferIterator end);
size_t timestamp() const; size_t timestamp() const;
size_t line_timestamp(LineCount line) const;
time_t fs_timestamp() const; time_t fs_timestamp() const;
void set_fs_timestamp(time_t ts); void set_fs_timestamp(time_t ts);
@ -180,7 +179,6 @@ private:
struct Line struct Line
{ {
size_t timestamp;
ByteCount start; ByteCount start;
String content; String content;

View File

@ -100,11 +100,6 @@ inline memoryview<Buffer::Change> Buffer::changes_since(size_t timestamp) const
m_changes.data() + m_changes.size() }; m_changes.data() + m_changes.size() };
} }
inline size_t Buffer::line_timestamp(LineCount line) const
{
return m_lines[line].timestamp;
}
inline ByteCoord Buffer::back_coord() const inline ByteCoord Buffer::back_coord() const
{ {
return { line_count() - 1, m_lines.back().length() - 1 }; return { line_count() - 1, m_lines.back().length() - 1 };

View File

@ -778,8 +778,9 @@ private:
erase = it->line <= prev.old_line + prev.num_removed; erase = it->line <= prev.old_line + prev.num_removed;
it->line += prev.diff(); it->line += prev.diff();
} }
erase = erase or (it->line >= buffer.line_count() or if (modif_it != modifs.end() and modif_it->old_line == it->line)
it->timestamp < buffer.line_timestamp(it->line)); erase = true;
erase = erase or (it->line >= buffer.line_count());
if (not erase) if (not erase)
{ {