From 753f3a50d10e43134ebeb52b3ec0a10b7ec2b80a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 29 Jan 2017 13:49:45 +0000 Subject: [PATCH] Make StringView and unit types trivial types --- src/command_manager.cc | 2 ++ src/file.cc | 2 +- src/insert_completer.cc | 2 +- src/main.cc | 2 +- src/ranked_match.hh | 2 +- src/string.hh | 8 +++++--- src/units.hh | 18 ++++++++++++++---- 7 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/command_manager.cc b/src/command_manager.cc index 44900c4f..6b79df3c 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -47,6 +47,8 @@ namespace struct Reader { public: + Reader(StringView s) : str{s}, pos{}, coord{} {} + [[gnu::always_inline]] char operator*() const { return str[pos]; } diff --git a/src/file.cc b/src/file.cc index 6c55050c..f5704d71 100644 --- a/src/file.cc +++ b/src/file.cc @@ -86,7 +86,7 @@ String real_path(StringView filename) char buffer[PATH_MAX+1]; StringView existing = filename; - StringView non_existing; + StringView non_existing{}; while (true) { diff --git a/src/insert_completer.cc b/src/insert_completer.cc index 239da7cc..90ce1b7d 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -516,7 +516,7 @@ bool InsertCompleter::try_complete(Func complete_func) kak_assert(m_completions.begin <= sels.main().cursor()); m_current_candidate = m_completions.candidates.size(); menu_show(); - m_completions.candidates.push_back({sels.buffer().string(m_completions.begin, m_completions.end), ""}); + m_completions.candidates.push_back({sels.buffer().string(m_completions.begin, m_completions.end), "", {}}); return true; } diff --git a/src/main.cc b/src/main.cc index a41ebad1..5e84812d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -249,7 +249,7 @@ void register_options() Vector({ "./", "/usr/include" })); reg.declare_option("completers", "insert mode completers to execute.", InsertCompleterDescList({ - InsertCompleterDesc{ InsertCompleterDesc::Filename }, + InsertCompleterDesc{ InsertCompleterDesc::Filename, {} }, InsertCompleterDesc{ InsertCompleterDesc::Word, "all"_str } }), OptionFlags::None); reg.declare_option("static_words", "list of words to always consider for insert word completion", diff --git a/src/ranked_match.hh b/src/ranked_match.hh index 4a56528a..bac6bc39 100644 --- a/src/ranked_match.hh +++ b/src/ranked_match.hh @@ -44,7 +44,7 @@ private: FullMatch = 1 << 5, }; - StringView m_candidate; + StringView m_candidate{}; Flags m_flags = Flags::None; int m_word_boundary_match_count = 0; int m_max_index = 0; diff --git a/src/string.hh b/src/string.hh index 8ce6ded5..14e92bd7 100644 --- a/src/string.hh +++ b/src/string.hh @@ -211,7 +211,7 @@ private: class StringView : public StringOps { public: - constexpr StringView() = default; + StringView() = default; constexpr StringView(const char* data, ByteCount length) : m_data{data}, m_length{length} {} constexpr StringView(const char* data) : m_data{data}, m_length{data ? strlen(data) : 0} {} @@ -248,10 +248,12 @@ public: ZeroTerminatedString zstr() const { return {begin(), end()}; } private: - const char* m_data = nullptr; - ByteCount m_length = 0; + const char* m_data; + ByteCount m_length; }; +static_assert(std::is_trivial::value, ""); + template inline StringView StringOps::substr(ByteCount from, ByteCount length) const { diff --git a/src/units.hh b/src/units.hh index e7f853e6..0218055f 100644 --- a/src/units.hh +++ b/src/units.hh @@ -13,6 +13,8 @@ template class StronglyTypedNumber { public: + StronglyTypedNumber() = default; + [[gnu::always_inline]] explicit constexpr StronglyTypedNumber(ValueType value) : m_value(value) @@ -124,8 +126,10 @@ protected: struct LineCount : public StronglyTypedNumber { + LineCount() = default; + [[gnu::always_inline]] - constexpr LineCount(int value = 0) : StronglyTypedNumber(value) {} + constexpr LineCount(int value) : StronglyTypedNumber(value) {} }; [[gnu::always_inline]] @@ -136,8 +140,10 @@ inline constexpr LineCount operator"" _line(unsigned long long int value) struct ByteCount : public StronglyTypedNumber { + ByteCount() = default; + [[gnu::always_inline]] - constexpr ByteCount(int value = 0) : StronglyTypedNumber(value) {} + constexpr ByteCount(int value) : StronglyTypedNumber(value) {} }; [[gnu::always_inline]] @@ -148,8 +154,10 @@ inline constexpr ByteCount operator"" _byte(unsigned long long int value) struct CharCount : public StronglyTypedNumber { + CharCount() = default; + [[gnu::always_inline]] - constexpr CharCount(int value = 0) : StronglyTypedNumber(value) {} + constexpr CharCount(int value) : StronglyTypedNumber(value) {} }; [[gnu::always_inline]] @@ -160,8 +168,10 @@ inline constexpr CharCount operator"" _char(unsigned long long int value) struct ColumnCount : public StronglyTypedNumber { + ColumnCount() = default; + [[gnu::always_inline]] - constexpr ColumnCount(int value = 0) : StronglyTypedNumber(value) {} + constexpr ColumnCount(int value) : StronglyTypedNumber(value) {} }; [[gnu::always_inline]]