From 32e01947fa1d56a171d64e9144a9a1ccfc1a250f Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 18 Oct 2011 13:59:32 +0000 Subject: [PATCH] DisplayBuffer: store atoms in a std::list instead of a vector --- src/display_buffer.cc | 14 +++++++------- src/display_buffer.hh | 2 +- src/filters.cc | 6 +++--- src/window.cc | 7 +++---- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/display_buffer.cc b/src/display_buffer.cc index c0e6ec77..64b2099e 100644 --- a/src/display_buffer.cc +++ b/src/display_buffer.cc @@ -98,7 +98,6 @@ DisplayBuffer::iterator DisplayBuffer::atom_containing(const BufferIterator& whe DisplayBuffer::iterator DisplayBuffer::split(iterator atom, const BufferIterator& pos) { - assert(atom < end()); assert(pos > atom->begin()); assert(pos < atom->end()); DisplayAtom new_atom(atom->coord(), atom->begin(), pos, @@ -113,21 +112,22 @@ DisplayBuffer::iterator DisplayBuffer::split(iterator atom, const BufferIterator void DisplayBuffer::check_invariant() const { - for (size_t i = 0; i < m_atoms.size(); ++i) + const_iterator prev_it; + for (const_iterator it = begin(); it != end(); ++it) { - assert(m_atoms[i].end() >= m_atoms[i].begin()); - if (i > 0) + assert(it->end() >= it->begin()); + if (it != begin()) { - assert(m_atoms[i-1].end() == m_atoms[i].begin()); - assert(m_atoms[i-1].end_coord() == m_atoms[i].coord()); + assert(prev_it->end() == it->begin()); + assert(prev_it->end_coord() == it->coord()); } + prev_it = it; } } void DisplayBuffer::replace_atom_content(iterator atom, const BufferString& replacement) { - assert(atom < end()); atom->m_replacement_text = replacement; // update coordinates of subsequents atoms diff --git a/src/display_buffer.hh b/src/display_buffer.hh index 5b7f432c..c351c219 100644 --- a/src/display_buffer.hh +++ b/src/display_buffer.hh @@ -93,7 +93,7 @@ private: class DisplayBuffer { public: - typedef std::vector AtomList; + typedef std::list AtomList; typedef AtomList::iterator iterator; typedef AtomList::const_iterator const_iterator; diff --git a/src/filters.cc b/src/filters.cc index 2f6450f5..7459c31f 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -15,7 +15,7 @@ void colorize_regex(DisplayBuffer& display_buffer, { const BufferIterator& begin = matches.begin()->first; if (begin != atom_it->begin()) - atom_it = display_buffer.split(atom_it, begin) + 1; + atom_it = ++display_buffer.split(atom_it, begin); const BufferIterator& end = matches.begin()->second; if (end != atom_it->end()) @@ -64,7 +64,7 @@ void expand_tabulations(DisplayBuffer& display_buffer) if (*it == '\t') { if (it != atom_it->begin()) - atom_it = display_buffer.split(atom_it, it) + 1; + atom_it = ++display_buffer.split(atom_it, it); if (it+1 != atom_it->end()) atom_it = display_buffer.split(atom_it, it+1); @@ -108,7 +108,7 @@ void show_line_numbers(DisplayBuffer& display_buffer) if (not atom_it->splitable()) continue; - atom_it = display_buffer.split(atom_it, line_start) + 1; + atom_it = ++display_buffer.split(atom_it, line_start); } atom_it = display_buffer.insert( atom_it, diff --git a/src/window.cc b/src/window.cc index 76eabce2..0f1714da 100644 --- a/src/window.cc +++ b/src/window.cc @@ -71,7 +71,7 @@ public: else if (atom.begin() < sel.begin() and atom.end() > sel.end()) { atom_it = display_buffer.split(atom_it, sel.begin()); - atom_it = display_buffer.split(atom_it + 1, sel.end()); + atom_it = display_buffer.split(++atom_it, sel.end()); atom_it->attribute() |= Attributes::Underline; ++atom_it; ++sel_it; @@ -79,7 +79,7 @@ public: // [------###] else if (atom.begin() < sel.begin() and atom.end() > sel.begin()) { - atom_it = display_buffer.split(atom_it, sel.begin()) + 1; + atom_it = ++display_buffer.split(atom_it, sel.begin()); atom_it->attribute() |= Attributes::Underline; ++atom_it; } @@ -225,8 +225,7 @@ BufferIterator Window::iterator_at(const DisplayCoord& window_pos) const { if (window_pos < atom_it->coord()) { - const DisplayAtom& atom = *(atom_it - 1); - return atom.iterator_at(window_pos); + return (--atom_it)->iterator_at(window_pos); } } }