From fffa405bfd86ec49fd27d7f9a903271409a0ea24 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 23 Oct 2011 20:26:30 +0000 Subject: [PATCH] DisplayBuffer: overload atom_containing with a version taking an iterator to search start --- src/display_buffer.cc | 10 ++++++++-- src/display_buffer.hh | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/display_buffer.cc b/src/display_buffer.cc index 64b2099e..a263d8f5 100644 --- a/src/display_buffer.cc +++ b/src/display_buffer.cc @@ -88,10 +88,16 @@ DisplayBuffer::iterator DisplayBuffer::insert(iterator where, const DisplayAtom& DisplayBuffer::iterator DisplayBuffer::atom_containing(const BufferIterator& where) { - for (iterator it = m_atoms.begin(); it != m_atoms.end(); ++it) + return atom_containing(where, m_atoms.begin()); +} + +DisplayBuffer::iterator DisplayBuffer::atom_containing(const BufferIterator& where, + iterator start) +{ + for (iterator it = start; it != m_atoms.end(); ++it) { if (it->end() > where) - return it; + return it->begin() <= where ? it : end(); } return end(); } diff --git a/src/display_buffer.hh b/src/display_buffer.hh index c351c219..b3cd8453 100644 --- a/src/display_buffer.hh +++ b/src/display_buffer.hh @@ -113,6 +113,7 @@ public: const_iterator end() const { return m_atoms.end(); } iterator atom_containing(const BufferIterator& where); + iterator atom_containing(const BufferIterator& where, iterator start); const DisplayAtom& front() const { return m_atoms.front(); } const DisplayAtom& back() const { return m_atoms.back(); }