get rid of Buffer::compute_lines

This commit is contained in:
Maxime Coste 2012-03-12 21:31:27 +00:00
parent 97b8905a6d
commit 3c105592e0
2 changed files with 7 additions and 15 deletions

View File

@ -26,10 +26,11 @@ Buffer::Buffer(const std::string& name, Type type,
const String& initial_content)
: m_name(name), m_type(type),
m_history(1), m_history_cursor(m_history.begin()),
m_content(initial_content), m_last_save_undo_index(0)
m_last_save_undo_index(0)
{
BufferManager::instance().register_buffer(this);
compute_lines();
if (not initial_content.empty())
apply_modification(Modification::make_insert(begin(), initial_content));
if (type == Type::NewFile)
GlobalHooksManager::instance().run_hook("BufCreate", name, Context(*this));
@ -185,17 +186,6 @@ bool Buffer::redo()
++m_history_cursor;
}
void Buffer::compute_lines()
{
m_lines.clear();
m_lines.push_back(0);
for (BufferPos i = 0; i + 1 < m_content.size(); ++i)
{
if (m_content[i] == '\n')
m_lines.push_back(i + 1);
}
}
void Buffer::update_lines(const Modification& modification)
{
size_t length = modification.content.length();
@ -275,6 +265,9 @@ void Buffer::apply_modification(const Modification& modification)
void Buffer::modify(Modification&& modification)
{
if (modification.content.empty())
return;
apply_modification(modification);
m_current_undo_group.push_back(std::move(modification));
}

View File

@ -172,11 +172,10 @@ private:
friend class BufferIterator;
std::vector<BufferPos> m_lines;
void update_lines(const Modification& modification);
void compute_lines();
BufferPos line_at(const BufferIterator& iterator) const;
BufferSize line_length(BufferPos line) const;
void update_lines(const Modification& modification);
String m_content;