From 3248829f5b6a225dbe2656bfaed377779bcdcbc7 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 12 Jan 2014 17:19:05 +0000 Subject: [PATCH] rename buffer_iterator.inl.hh as buffer.inl.hh and inline some more methods --- src/buffer.cc | 80 ----------------- src/buffer.hh | 2 +- src/{buffer_iterator.inl.hh => buffer.inl.hh} | 86 ++++++++++++++++++- 3 files changed, 84 insertions(+), 84 deletions(-) rename src/{buffer_iterator.inl.hh => buffer.inl.hh} (55%) diff --git a/src/buffer.cc b/src/buffer.cc index 0e59e36f..e6d8c1db 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -157,30 +157,6 @@ BufferCoord Buffer::offset_coord(BufferCoord coord, LineCount offset) return {line, content.byte_count_to(character)}; } -BufferIterator Buffer::begin() const -{ - return BufferIterator(*this, { 0_line, 0 }); -} - -BufferIterator Buffer::end() const -{ - if (m_lines.empty()) - return BufferIterator(*this, { 0_line, 0 }); - return BufferIterator(*this, { line_count()-1, m_lines.back().length() }); -} - -ByteCount Buffer::byte_count() const -{ - if (m_lines.empty()) - return 0; - return m_lines.back().start + m_lines.back().length(); -} - -LineCount Buffer::line_count() const -{ - return LineCount(m_lines.size()); -} - String Buffer::string(BufferCoord begin, BufferCoord end) const { String res; @@ -674,20 +650,6 @@ BufferCoord Buffer::advance(BufferCoord coord, ByteCount count) const return { LineCount{ (int)(it - m_lines.begin()) }, off - it->start }; } -BufferCoord Buffer::next(BufferCoord coord) const -{ - if (coord.column < m_lines[coord.line].length() - 1) - ++coord.column; - else if (coord.line == m_lines.size() - 1) - coord.column = m_lines.back().length(); - else - { - ++coord.line; - coord.column = 0; - } - return coord; -} - BufferCoord Buffer::char_next(BufferCoord coord) const { if (coord.column < m_lines[coord.line].length() - 1) @@ -711,18 +673,6 @@ BufferCoord Buffer::char_next(BufferCoord coord) const return coord; } -BufferCoord Buffer::prev(BufferCoord coord) const -{ - if (coord.column == 0) - { - if (coord.line > 0) - coord.column = m_lines[--coord.line].length() - 1; - } - else - --coord.column; - return coord; -} - BufferCoord Buffer::char_prev(BufferCoord coord) const { kak_assert(is_valid(coord)); @@ -741,36 +691,6 @@ BufferCoord Buffer::char_prev(BufferCoord coord) const return coord; } -ByteCount Buffer::distance(BufferCoord begin, BufferCoord end) const -{ - return offset(end) - offset(begin); -} - -ByteCount Buffer::offset(BufferCoord c) const -{ - if (c.line == line_count()) - return m_lines.back().start + m_lines.back().length(); - return m_lines[c.line].start + c.column; -} - -bool Buffer::is_valid(BufferCoord c) const -{ - return (c.line < line_count() and c.column < m_lines[c.line].length()) or - (c.line == line_count() - 1 and c.column == m_lines.back().length()) or - (c.line == line_count() and c.column == 0); -} - -bool Buffer::is_end(BufferCoord c) const -{ - return c >= BufferCoord{line_count() - 1, m_lines.back().length()}; -} - -char Buffer::byte_at(BufferCoord c) const -{ - kak_assert(c.line < line_count() and c.column < m_lines[c.line].length()); - return m_lines[c.line].content[c.column]; -} - time_t Buffer::fs_timestamp() const { kak_assert(m_flags & Flags::File); diff --git a/src/buffer.hh b/src/buffer.hh index 347be959..3ea77fa8 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -287,6 +287,6 @@ public: } -#include "buffer_iterator.inl.hh" +#include "buffer.inl.hh" #endif // buffer_hh_INCLUDED diff --git a/src/buffer_iterator.inl.hh b/src/buffer.inl.hh similarity index 55% rename from src/buffer_iterator.inl.hh rename to src/buffer.inl.hh index 4e5540e7..b8fc1400 100644 --- a/src/buffer_iterator.inl.hh +++ b/src/buffer.inl.hh @@ -1,11 +1,91 @@ -#ifndef buffer_iterator_inl_h_INCLUDED -#define buffer_iterator_inl_h_INCLUDED +#ifndef buffer_inl_h_INCLUDED +#define buffer_inl_h_INCLUDED #include "assert.hh" namespace Kakoune { +inline char Buffer::byte_at(BufferCoord c) const +{ + kak_assert(c.line < line_count() and c.column < m_lines[c.line].length()); + return m_lines[c.line].content[c.column]; +} + +inline BufferCoord Buffer::next(BufferCoord coord) const +{ + if (coord.column < m_lines[coord.line].length() - 1) + ++coord.column; + else if (coord.line == m_lines.size() - 1) + coord.column = m_lines.back().length(); + else + { + ++coord.line; + coord.column = 0; + } + return coord; +} + +inline BufferCoord Buffer::prev(BufferCoord coord) const +{ + if (coord.column == 0) + { + if (coord.line > 0) + coord.column = m_lines[--coord.line].length() - 1; + } + else + --coord.column; + return coord; +} + +inline ByteCount Buffer::distance(BufferCoord begin, BufferCoord end) const +{ + return offset(end) - offset(begin); +} + +inline ByteCount Buffer::offset(BufferCoord c) const +{ + if (c.line == line_count()) + return m_lines.back().start + m_lines.back().length(); + return m_lines[c.line].start + c.column; +} + +inline bool Buffer::is_valid(BufferCoord c) const +{ + return (c.line < line_count() and c.column < m_lines[c.line].length()) or + (c.line == line_count() - 1 and c.column == m_lines.back().length()) or + (c.line == line_count() and c.column == 0); +} + +inline bool Buffer::is_end(BufferCoord c) const +{ + return c >= BufferCoord{line_count() - 1, m_lines.back().length()}; +} + +inline BufferIterator Buffer::begin() const +{ + return BufferIterator(*this, { 0_line, 0 }); +} + +inline BufferIterator Buffer::end() const +{ + if (m_lines.empty()) + return BufferIterator(*this, { 0_line, 0 }); + return BufferIterator(*this, { line_count()-1, m_lines.back().length() }); +} + +inline ByteCount Buffer::byte_count() const +{ + if (m_lines.empty()) + return 0; + return m_lines.back().start + m_lines.back().length(); +} + +inline LineCount Buffer::line_count() const +{ + return LineCount(m_lines.size()); +} + inline BufferIterator::BufferIterator(const Buffer& buffer, BufferCoord coord) : m_buffer(&buffer), m_coord(coord) { @@ -110,4 +190,4 @@ inline BufferIterator BufferIterator::operator--(int) } } -#endif // buffer_iterator_inl_h_INCLUDED +#endif // buffer_inl_h_INCLUDED