diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2012-03-12 21:31:27 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2012-03-12 21:31:27 +0000 |
| commit | 3c105592e0ebc9e83938d6a90ca4bd1fbb6fdd2d (patch) | |
| tree | 288d9c44bbee6d5fb5bedcecc370f2740956dc06 /src | |
| parent | 97b8905a6de553d0905f40cb2d2c2bfcd341bdb7 (diff) | |
get rid of Buffer::compute_lines
Diffstat (limited to 'src')
| -rw-r--r-- | src/buffer.cc | 19 | ||||
| -rw-r--r-- | src/buffer.hh | 3 |
2 files changed, 7 insertions, 15 deletions
diff --git a/src/buffer.cc b/src/buffer.cc index 707981b8..6bea08c7 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -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)); } diff --git a/src/buffer.hh b/src/buffer.hh index 6e881e92..00b7764c 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -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; |
