Change BufferIterator comparison to assert same buffer
Comparing iterators between buffers should never happen, and the only place we did was with default constructed BufferIterator which we replace by casting the iterator to bool. This should improve performance on iterator heavy code.
This commit is contained in:
parent
91d45a100a
commit
b7b036c210
|
@ -75,6 +75,8 @@ public:
|
||||||
const char& operator[](size_t n) const noexcept;
|
const char& operator[](size_t n) const noexcept;
|
||||||
size_t operator- (const BufferIterator& iterator) const;
|
size_t operator- (const BufferIterator& iterator) const;
|
||||||
|
|
||||||
|
explicit operator bool() const { return static_cast<bool>(m_buffer); }
|
||||||
|
|
||||||
BufferIterator operator+ (ByteCount size) const;
|
BufferIterator operator+ (ByteCount size) const;
|
||||||
BufferIterator operator- (ByteCount size) const;
|
BufferIterator operator- (ByteCount size) const;
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,8 @@ inline BufferIterator::BufferIterator(const Buffer& buffer, BufferCoord coord) n
|
||||||
|
|
||||||
inline bool BufferIterator::operator==(const BufferIterator& iterator) const noexcept
|
inline bool BufferIterator::operator==(const BufferIterator& iterator) const noexcept
|
||||||
{
|
{
|
||||||
return m_buffer == iterator.m_buffer and m_coord == iterator.m_coord;
|
kak_assert(m_buffer == iterator.m_buffer);
|
||||||
|
return m_coord == iterator.m_coord;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::strong_ordering BufferIterator::operator<=>(const BufferIterator& iterator) const noexcept
|
inline std::strong_ordering BufferIterator::operator<=>(const BufferIterator& iterator) const noexcept
|
||||||
|
|
|
@ -39,7 +39,7 @@ struct MatchResults
|
||||||
{
|
{
|
||||||
SubMatch() = default;
|
SubMatch() = default;
|
||||||
SubMatch(Iterator begin, Iterator end)
|
SubMatch(Iterator begin, Iterator end)
|
||||||
: std::pair<Iterator, Iterator>{begin, end}, matched{begin != Iterator{}}
|
: std::pair<Iterator, Iterator>{begin, end}, matched{static_cast<bool>(begin)}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool matched = false;
|
bool matched = false;
|
||||||
|
|
|
@ -483,7 +483,7 @@ select_sentence(const Context& context, const Selection& selection,
|
||||||
BufferIterator first = buffer.iterator_at(selection.cursor());
|
BufferIterator first = buffer.iterator_at(selection.cursor());
|
||||||
BufferIterator last;
|
BufferIterator last;
|
||||||
|
|
||||||
for (++count; count > 0; --count)
|
for (int i = 0; i <= count; ++i)
|
||||||
{
|
{
|
||||||
if (not (flags & ObjectFlags::ToEnd) and first != buffer.begin())
|
if (not (flags & ObjectFlags::ToEnd) and first != buffer.begin())
|
||||||
{
|
{
|
||||||
|
@ -494,7 +494,7 @@ select_sentence(const Context& context, const Selection& selection,
|
||||||
first = prev_non_blank;
|
first = prev_non_blank;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (last == BufferIterator{})
|
if (i == 0)
|
||||||
last = first;
|
last = first;
|
||||||
|
|
||||||
if (flags & ObjectFlags::ToBegin)
|
if (flags & ObjectFlags::ToBegin)
|
||||||
|
@ -552,7 +552,7 @@ select_paragraph(const Context& context, const Selection& selection,
|
||||||
BufferIterator first = buffer.iterator_at(selection.cursor());
|
BufferIterator first = buffer.iterator_at(selection.cursor());
|
||||||
BufferIterator last;
|
BufferIterator last;
|
||||||
|
|
||||||
for (++count; count > 0; --count)
|
for (int i = 0; i <= count; ++i)
|
||||||
{
|
{
|
||||||
if (not (flags & ObjectFlags::ToEnd) and first.coord() > BufferCoord{0,1} and
|
if (not (flags & ObjectFlags::ToEnd) and first.coord() > BufferCoord{0,1} and
|
||||||
is_eol(*(first-1)) and first-1 != buffer.begin() and is_eol(*(first-2)))
|
is_eol(*(first-1)) and first-1 != buffer.begin() and is_eol(*(first-2)))
|
||||||
|
@ -561,7 +561,7 @@ select_paragraph(const Context& context, const Selection& selection,
|
||||||
first != buffer.begin() and (first+1) != buffer.end() and
|
first != buffer.begin() and (first+1) != buffer.end() and
|
||||||
is_eol(*(first-1)) and is_eol(*first))
|
is_eol(*(first-1)) and is_eol(*first))
|
||||||
++first;
|
++first;
|
||||||
if (last == BufferIterator{})
|
if (i == 0)
|
||||||
last = first;
|
last = first;
|
||||||
|
|
||||||
if ((flags & ObjectFlags::ToBegin) and first != buffer.begin())
|
if ((flags & ObjectFlags::ToBegin) and first != buffer.begin())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user