noexept-ify BufferIterator methods

This commit is contained in:
Maxime Coste 2017-06-07 10:58:01 +01:00
parent 502c5da0e9
commit cb6ef4afb6
2 changed files with 21 additions and 24 deletions

View File

@ -59,18 +59,18 @@ public:
// costly, so this is not strictly random access
using iterator_category = std::bidirectional_iterator_tag;
BufferIterator() : m_buffer(nullptr) {}
BufferIterator(const Buffer& buffer, BufferCoord coord);
BufferIterator() noexcept : m_buffer(nullptr) {}
BufferIterator(const Buffer& buffer, BufferCoord coord) noexcept;
bool operator== (const BufferIterator& iterator) const;
bool operator!= (const BufferIterator& iterator) const;
bool operator< (const BufferIterator& iterator) const;
bool operator<= (const BufferIterator& iterator) const;
bool operator> (const BufferIterator& iterator) const;
bool operator>= (const BufferIterator& iterator) const;
bool operator== (const BufferIterator& iterator) const noexcept;
bool operator!= (const BufferIterator& iterator) const noexcept;
bool operator< (const BufferIterator& iterator) const noexcept;
bool operator<= (const BufferIterator& iterator) const noexcept;
bool operator> (const BufferIterator& iterator) const noexcept;
bool operator>= (const BufferIterator& iterator) const noexcept;
const char& operator* () const;
const char& operator[](size_t n) const;
const char& operator* () const noexcept;
const char& operator[](size_t n) const noexcept;
size_t operator- (const BufferIterator& iterator) const;
BufferIterator operator+ (ByteCount size) const;
@ -85,7 +85,7 @@ public:
BufferIterator operator++ (int);
BufferIterator operator-- (int);
const BufferCoord& coord() const { return m_coord; }
const BufferCoord& coord() const noexcept { return m_coord; }
private:
SafePtr<const Buffer> m_buffer;

View File

@ -114,55 +114,52 @@ inline BufferCoord Buffer::end_coord() const
BufferCoord{0,0} : BufferCoord{ line_count() - 1, m_lines.back().length() };
}
inline BufferIterator::BufferIterator(const Buffer& buffer, BufferCoord coord)
inline BufferIterator::BufferIterator(const Buffer& buffer, BufferCoord coord) noexcept
: m_buffer(&buffer), m_coord(coord),
m_line((*m_buffer)[coord.line]),
m_last_line(buffer.line_count()-1)
{
kak_assert(m_buffer and m_buffer->is_valid(m_coord));
}
m_last_line(buffer.line_count()-1) {}
inline bool BufferIterator::operator==(const BufferIterator& iterator) const
inline bool BufferIterator::operator==(const BufferIterator& iterator) const noexcept
{
return m_buffer == iterator.m_buffer and m_coord == iterator.m_coord;
}
inline bool BufferIterator::operator!=(const BufferIterator& iterator) const
inline bool BufferIterator::operator!=(const BufferIterator& iterator) const noexcept
{
return m_buffer != iterator.m_buffer or m_coord != iterator.m_coord;
}
inline bool BufferIterator::operator<(const BufferIterator& iterator) const
inline bool BufferIterator::operator<(const BufferIterator& iterator) const noexcept
{
kak_assert(m_buffer == iterator.m_buffer);
return (m_coord < iterator.m_coord);
}
inline bool BufferIterator::operator<=(const BufferIterator& iterator) const
inline bool BufferIterator::operator<=(const BufferIterator& iterator) const noexcept
{
kak_assert(m_buffer == iterator.m_buffer);
return (m_coord <= iterator.m_coord);
}
inline bool BufferIterator::operator>(const BufferIterator& iterator) const
inline bool BufferIterator::operator>(const BufferIterator& iterator) const noexcept
{
kak_assert(m_buffer == iterator.m_buffer);
return (m_coord > iterator.m_coord);
}
inline bool BufferIterator::operator>=(const BufferIterator& iterator) const
inline bool BufferIterator::operator>=(const BufferIterator& iterator) const noexcept
{
kak_assert(m_buffer == iterator.m_buffer);
return (m_coord >= iterator.m_coord);
}
[[gnu::always_inline]]
inline const char& BufferIterator::operator*() const
inline const char& BufferIterator::operator*() const noexcept
{
return m_line[m_coord.column];
}
inline const char& BufferIterator::operator[](size_t n) const
inline const char& BufferIterator::operator[](size_t n) const noexcept
{
return m_buffer->byte_at(m_buffer->advance(m_coord, n));
}