From 30d9e10ac68ac91251b2ba6c1fb2a0fd76e9d5b2 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 29 May 2012 00:33:55 +0000 Subject: [PATCH] DisplayBuffer optimization, suppressed some paranoid checks --- src/buffer.hh | 4 ++-- src/display_buffer.cc | 26 ++++++++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/buffer.hh b/src/buffer.hh index 71d7b2ac..950b53b8 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -70,10 +70,10 @@ public: void on_erase(const BufferCoord& begin, const BufferCoord& end); const Buffer& buffer() const; - -private: BufferSize line() const { return m_coord.line; } BufferSize column() const { return m_coord.column; } + +private: BufferSize offset() const; const Buffer* m_buffer; diff --git a/src/display_buffer.cc b/src/display_buffer.cc index 2ecded59..303f1b26 100644 --- a/src/display_buffer.cc +++ b/src/display_buffer.cc @@ -14,32 +14,38 @@ String DisplayAtom::content() const return m_replacement_text; } -template static DisplayCoord advance_coord(const DisplayCoord& pos, - Iterator begin, Iterator end) + const BufferIterator& begin, + const BufferIterator& end) +{ + if (begin.line() == end.line()) + return DisplayCoord(pos.line, pos.column + end.column() - begin.column()); + else + return DisplayCoord(pos.line + end.line() - begin.line(), end.column()); +} + +static DisplayCoord advance_coord(const DisplayCoord& pos, + const String& str) { DisplayCoord res = pos; - while (begin != end) + for (auto c : str) { - if (*begin == '\n') + if (c == '\n') { ++res.line; res.column = 0; } else ++res.column; - ++begin; } return res; } - DisplayCoord DisplayAtom::end_coord() const { if (m_replacement_text.empty()) return advance_coord(m_coord, m_begin, m_end); else - return advance_coord(m_coord, m_replacement_text.begin(), - m_replacement_text.end()); + return advance_coord(m_coord, m_replacement_text); } BufferIterator DisplayAtom::iterator_at(const DisplayCoord& coord) const @@ -81,7 +87,7 @@ DisplayBuffer::DisplayBuffer() DisplayBuffer::iterator DisplayBuffer::insert(iterator where, const DisplayAtom& atom) { iterator res = m_atoms.insert(where, atom); - check_invariant(); + // check_invariant(); return res; } @@ -115,7 +121,7 @@ DisplayBuffer::iterator DisplayBuffer::split(iterator atom, const BufferIterator iterator insert_pos = atom; ++insert_pos; m_atoms.insert(insert_pos, std::move(new_atom)); - check_invariant(); + // check_invariant(); return atom; }