From f8106690b1ea1f307671bb347cc86869c1c88d2c Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 27 Jan 2016 08:27:23 +0000 Subject: [PATCH] Make BufferIterator::operator* return a const ref to be more compatible --- src/buffer.hh | 6 +++--- src/buffer.inl.hh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/buffer.hh b/src/buffer.hh index 60820487..c8870509 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -64,8 +64,8 @@ public: bool operator> (const BufferIterator& iterator) const; bool operator>= (const BufferIterator& iterator) const; - char operator* () const; - char operator[](size_t n) const; + const char& operator* () const; + const char& operator[](size_t n) const; size_t operator- (const BufferIterator& iterator) const; BufferIterator operator+ (ByteCount size) const; @@ -133,7 +133,7 @@ public: String string(ByteCoord begin, ByteCoord end) const; - char byte_at(ByteCoord c) const; + const char& byte_at(ByteCoord c) const; ByteCount distance(ByteCoord begin, ByteCoord end) const; ByteCoord advance(ByteCoord coord, ByteCount count) const; ByteCoord next(ByteCoord coord) const; diff --git a/src/buffer.inl.hh b/src/buffer.inl.hh index cabec9c8..d6af3d4a 100644 --- a/src/buffer.inl.hh +++ b/src/buffer.inl.hh @@ -7,7 +7,7 @@ namespace Kakoune { [[gnu::always_inline]] -inline char Buffer::byte_at(ByteCoord c) const +inline const char& Buffer::byte_at(ByteCoord c) const { kak_assert(c.line < line_count() and c.column < m_lines[c.line].length()); return m_lines[c.line][c.column]; @@ -152,12 +152,12 @@ inline bool BufferIterator::operator>=(const BufferIterator& iterator) const } [[gnu::always_inline]] -inline char BufferIterator::operator*() const +inline const char& BufferIterator::operator*() const { return m_buffer->byte_at(m_coord); } -inline char BufferIterator::operator[](size_t n) const +inline const char& BufferIterator::operator[](size_t n) const { return m_buffer->byte_at(m_buffer->advance(m_coord, n)); }