Make StringView and unit types trivial types
This commit is contained in:
parent
0cb192921a
commit
753f3a50d1
|
@ -47,6 +47,8 @@ namespace
|
||||||
struct Reader
|
struct Reader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Reader(StringView s) : str{s}, pos{}, coord{} {}
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
char operator*() const { return str[pos]; }
|
char operator*() const { return str[pos]; }
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ String real_path(StringView filename)
|
||||||
char buffer[PATH_MAX+1];
|
char buffer[PATH_MAX+1];
|
||||||
|
|
||||||
StringView existing = filename;
|
StringView existing = filename;
|
||||||
StringView non_existing;
|
StringView non_existing{};
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
|
|
@ -516,7 +516,7 @@ bool InsertCompleter::try_complete(Func complete_func)
|
||||||
kak_assert(m_completions.begin <= sels.main().cursor());
|
kak_assert(m_completions.begin <= sels.main().cursor());
|
||||||
m_current_candidate = m_completions.candidates.size();
|
m_current_candidate = m_completions.candidates.size();
|
||||||
menu_show();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -249,7 +249,7 @@ void register_options()
|
||||||
Vector<String, MemoryDomain::Options>({ "./", "/usr/include" }));
|
Vector<String, MemoryDomain::Options>({ "./", "/usr/include" }));
|
||||||
reg.declare_option("completers", "insert mode completers to execute.",
|
reg.declare_option("completers", "insert mode completers to execute.",
|
||||||
InsertCompleterDescList({
|
InsertCompleterDescList({
|
||||||
InsertCompleterDesc{ InsertCompleterDesc::Filename },
|
InsertCompleterDesc{ InsertCompleterDesc::Filename, {} },
|
||||||
InsertCompleterDesc{ InsertCompleterDesc::Word, "all"_str }
|
InsertCompleterDesc{ InsertCompleterDesc::Word, "all"_str }
|
||||||
}), OptionFlags::None);
|
}), OptionFlags::None);
|
||||||
reg.declare_option("static_words", "list of words to always consider for insert word completion",
|
reg.declare_option("static_words", "list of words to always consider for insert word completion",
|
||||||
|
|
|
@ -44,7 +44,7 @@ private:
|
||||||
FullMatch = 1 << 5,
|
FullMatch = 1 << 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
StringView m_candidate;
|
StringView m_candidate{};
|
||||||
Flags m_flags = Flags::None;
|
Flags m_flags = Flags::None;
|
||||||
int m_word_boundary_match_count = 0;
|
int m_word_boundary_match_count = 0;
|
||||||
int m_max_index = 0;
|
int m_max_index = 0;
|
||||||
|
|
|
@ -211,7 +211,7 @@ private:
|
||||||
class StringView : public StringOps<StringView, const char>
|
class StringView : public StringOps<StringView, const char>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
constexpr StringView() = default;
|
StringView() = default;
|
||||||
constexpr StringView(const char* data, ByteCount length)
|
constexpr StringView(const char* data, ByteCount length)
|
||||||
: m_data{data}, m_length{length} {}
|
: m_data{data}, m_length{length} {}
|
||||||
constexpr StringView(const char* data) : m_data{data}, m_length{data ? strlen(data) : 0} {}
|
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()}; }
|
ZeroTerminatedString zstr() const { return {begin(), end()}; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char* m_data = nullptr;
|
const char* m_data;
|
||||||
ByteCount m_length = 0;
|
ByteCount m_length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static_assert(std::is_trivial<StringView>::value, "");
|
||||||
|
|
||||||
template<typename Type, typename CharType>
|
template<typename Type, typename CharType>
|
||||||
inline StringView StringOps<Type, CharType>::substr(ByteCount from, ByteCount length) const
|
inline StringView StringOps<Type, CharType>::substr(ByteCount from, ByteCount length) const
|
||||||
{
|
{
|
||||||
|
|
18
src/units.hh
18
src/units.hh
|
@ -13,6 +13,8 @@ template<typename RealType, typename ValueType = int>
|
||||||
class StronglyTypedNumber
|
class StronglyTypedNumber
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
StronglyTypedNumber() = default;
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
explicit constexpr StronglyTypedNumber(ValueType value)
|
explicit constexpr StronglyTypedNumber(ValueType value)
|
||||||
: m_value(value)
|
: m_value(value)
|
||||||
|
@ -124,8 +126,10 @@ protected:
|
||||||
|
|
||||||
struct LineCount : public StronglyTypedNumber<LineCount, int>
|
struct LineCount : public StronglyTypedNumber<LineCount, int>
|
||||||
{
|
{
|
||||||
|
LineCount() = default;
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
constexpr LineCount(int value = 0) : StronglyTypedNumber<LineCount>(value) {}
|
constexpr LineCount(int value) : StronglyTypedNumber<LineCount>(value) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
|
@ -136,8 +140,10 @@ inline constexpr LineCount operator"" _line(unsigned long long int value)
|
||||||
|
|
||||||
struct ByteCount : public StronglyTypedNumber<ByteCount, int>
|
struct ByteCount : public StronglyTypedNumber<ByteCount, int>
|
||||||
{
|
{
|
||||||
|
ByteCount() = default;
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
constexpr ByteCount(int value = 0) : StronglyTypedNumber<ByteCount>(value) {}
|
constexpr ByteCount(int value) : StronglyTypedNumber<ByteCount>(value) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
|
@ -148,8 +154,10 @@ inline constexpr ByteCount operator"" _byte(unsigned long long int value)
|
||||||
|
|
||||||
struct CharCount : public StronglyTypedNumber<CharCount, int>
|
struct CharCount : public StronglyTypedNumber<CharCount, int>
|
||||||
{
|
{
|
||||||
|
CharCount() = default;
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
constexpr CharCount(int value = 0) : StronglyTypedNumber<CharCount>(value) {}
|
constexpr CharCount(int value) : StronglyTypedNumber<CharCount>(value) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
|
@ -160,8 +168,10 @@ inline constexpr CharCount operator"" _char(unsigned long long int value)
|
||||||
|
|
||||||
struct ColumnCount : public StronglyTypedNumber<ColumnCount, int>
|
struct ColumnCount : public StronglyTypedNumber<ColumnCount, int>
|
||||||
{
|
{
|
||||||
|
ColumnCount() = default;
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
constexpr ColumnCount(int value = 0) : StronglyTypedNumber<ColumnCount>(value) {}
|
constexpr ColumnCount(int value) : StronglyTypedNumber<ColumnCount>(value) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user