diff --git a/src/Makefile b/src/Makefile index f927d9e3..f0ac8aa3 100644 --- a/src/Makefile +++ b/src/Makefile @@ -5,6 +5,17 @@ deps := $(addprefix ., $(sources:.cc=.d)) CXXFLAGS += -std=c++0x -g -Wall -Wno-reorder -Wno-sign-compare LDFLAGS += -lmenu -lncursesw -lboost_regex +debug ?= yes +ifeq ($(debug),yes) + CXXFLAGS += -DKAK_DEBUG +else + ifeq ($(debug),no) + CXXFLAGS += -O3 + else + $(error debug should be either yes or no) + endif +endif + kak : $(objects) $(CXX) $(LDFLAGS) $(CXXFLAGS) $(objects) -o $@ diff --git a/src/assert.hh b/src/assert.hh index 182b58a4..52bdcf48 100644 --- a/src/assert.hh +++ b/src/assert.hh @@ -16,8 +16,14 @@ void on_assert_failed(const char* message); #undef assert #endif -#define assert(condition) \ - if (not (condition)) \ - on_assert_failed("assert failed \"" #condition "\" at " __FILE__ ":" TOSTRING(__LINE__)) +#ifdef KAK_DEBUG + #define assert(condition) \ + if (not (condition)) \ + on_assert_failed("assert failed \"" #condition \ + "\" at " __FILE__ ":" TOSTRING(__LINE__)) +#else + #define assert(condition) +#endif + #endif // assert_hh_INCLUDED diff --git a/src/buffer.cc b/src/buffer.cc index 3c919c19..a73f8fd3 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -225,6 +225,7 @@ bool Buffer::redo() void Buffer::check_invariant() const { +#ifdef KAK_DEBUG ByteCount start = 0; assert(not m_lines.empty()); for (auto& line : m_lines) @@ -234,6 +235,7 @@ void Buffer::check_invariant() const assert(line.content.back() == '\n'); start += line.length(); } +#endif } void Buffer::do_insert(const BufferIterator& pos, const String& content) diff --git a/src/commands.cc b/src/commands.cc index 88271505..c7247016 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -27,11 +27,6 @@ namespace Kakoune { -using namespace std::placeholders; - -// berk -extern bool quit_requested; - namespace { diff --git a/src/editor.cc b/src/editor.cc index 1567608e..77080312 100644 --- a/src/editor.cc +++ b/src/editor.cc @@ -376,6 +376,7 @@ bool Editor::redo() void Editor::check_invariant() const { +#ifdef KAK_DEBUG assert(not m_selections.empty()); m_selections.check_invariant(); @@ -383,6 +384,7 @@ void Editor::check_invariant() const compare_selections); assert(std::is_sorted(m_selections.begin(), it, compare_selections)); assert(std::is_sorted(it, m_selections.end(), compare_selections)); +#endif } void Editor::begin_edition() diff --git a/src/parameters_parser.cc b/src/parameters_parser.cc index cdcfb0c1..1bf1e4d2 100644 --- a/src/parameters_parser.cc +++ b/src/parameters_parser.cc @@ -48,9 +48,11 @@ bool ParametersParser::has_option(const String& name) const const String& ParametersParser::option_value(const String& name) const { +#ifdef KAK_DEBUG auto it = m_options.find(name); assert(it != m_options.end()); assert(it->second == true); +#endif for (size_t i = 0; i < m_params.size(); ++i) { diff --git a/src/selection.cc b/src/selection.cc index 77511c00..04ebae81 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -26,10 +26,12 @@ BufferIterator Range::end() const void Range::check_invariant() const { +#ifdef KAK_DEBUG assert(m_first.is_valid()); assert(m_last.is_valid()); assert(utf8::is_character_start(m_first)); assert(utf8::is_character_start(m_last)); +#endif } static void avoid_eol(BufferIterator& it)