do not check buffer invariant in do_{erase,insert} as this cause O(n²) behaviour

This commit is contained in:
Maxime Coste 2013-04-03 19:22:12 +02:00
parent 4fbe2dc6bc
commit 1fd99e7e88
4 changed files with 5 additions and 9 deletions

View File

@ -321,8 +321,6 @@ void Buffer::do_insert(const BufferIterator& pos, const String& content)
end_it = BufferIterator{*this, { last_line, m_lines[last_line].length() - suffix.length() }};
}
check_invariant();
for (auto listener : m_change_listeners)
listener->on_insert(begin_it, end_it);
}
@ -348,8 +346,6 @@ void Buffer::do_erase(const BufferIterator& begin, const BufferIterator& end)
for (LineCount i = begin.line()+1; i < line_count(); ++i)
m_lines[i].start -= length;
check_invariant();
for (auto listener : m_change_listeners)
listener->on_erase(begin, end);
}

View File

@ -168,10 +168,10 @@ public:
const HookManager& hooks() const { return m_hooks; }
std::unordered_set<BufferChangeListener*>& change_listeners() const { return m_change_listeners; }
private:
friend class BufferIterator;
void check_invariant() const;
private:
friend class BufferIterator;
struct Line
{

View File

@ -88,10 +88,10 @@ void Editor::insert(const String& str, InsertMode mode)
{
sel.first() = pos;
sel.last() = str.empty() ? pos : utf8::character_start(pos + str.length() - 1);
sel.check_invariant();
}
sel.avoid_eol();
}
check_invariant();
}
void Editor::insert(const memoryview<String>& strings, InsertMode mode)
@ -110,10 +110,10 @@ void Editor::insert(const memoryview<String>& strings, InsertMode mode)
{
sel.first() = pos;
sel.last() = str.empty() ? pos : utf8::character_start(pos + str.length() - 1);
sel.check_invariant();
}
sel.avoid_eol();
}
check_invariant();
}
std::vector<String> Editor::selections_content() const
@ -408,6 +408,7 @@ void Editor::check_invariant() const
assert(not m_selections.empty());
assert(m_main_sel < m_selections.size());
m_selections.check_invariant();
buffer().check_invariant();
assert(std::is_sorted(m_selections.begin(), m_selections.end(), compare_selections));
#endif
}

View File

@ -87,7 +87,6 @@ public:
size_t cursor_pos = String::npos);
bool is_editing() const { return m_edition_level!= 0; }
private:
friend struct scoped_edition;
void begin_edition();