From 4c4b6a404dff8c3e22d4ddfe52b3bf21f946e098 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 3 May 2013 13:38:48 +0200 Subject: [PATCH] add SelectionList::check_invariant --- src/dynamic_selection_list.cc | 9 ++++----- src/selection.cc | 13 +++++++++++++ src/selection.hh | 2 ++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/dynamic_selection_list.cc b/src/dynamic_selection_list.cc index e6e32f6d..ab8dc26b 100644 --- a/src/dynamic_selection_list.cc +++ b/src/dynamic_selection_list.cc @@ -21,12 +21,11 @@ DynamicSelectionList& DynamicSelectionList::operator=(SelectionList selections) void DynamicSelectionList::check_invariant() const { #ifdef KAK_DEBUG + if (empty()) + return; const Buffer* buf = &buffer(); - for (auto& sel : *this) - { - kak_assert(buf == &sel.buffer()); - sel.check_invariant(); - } + kak_assert(&front().buffer() == buf); + SelectionList::check_invariant(); #endif } diff --git a/src/selection.cc b/src/selection.cc index 0e6bd710..8830e9e5 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -142,4 +142,17 @@ void SelectionList::update_erase(const BufferCoord& begin, const BufferCoord& en on_buffer_change(*this, begin, end, end.line); } +void SelectionList::check_invariant() const +{ +#ifdef KAK_DEBUG + for (size_t i = 0; i < size(); ++i) + { + auto& sel = (*this)[i]; + sel.check_invariant(); + if (i+1 < size()) + kak_assert(sel.begin() <= (*this)[i+1].begin()); + } +#endif +} + } diff --git a/src/selection.hh b/src/selection.hh index 50b8ad7c..d24bc87e 100644 --- a/src/selection.hh +++ b/src/selection.hh @@ -74,6 +74,8 @@ struct SelectionList : std::vector void update_insert(const BufferCoord& begin, const BufferCoord& end); void update_erase(const BufferCoord& begin, const BufferCoord& end); + + void check_invariant() const; }; }