refactor: make a few more methods constexpr (#5798)

This commit is contained in:
Charles Kerr
2023-07-15 19:02:39 -05:00
committed by GitHub
parent 31f2c7aa29
commit 273f943a3b
3 changed files with 11 additions and 7 deletions

View File

@@ -33,24 +33,28 @@ struct Handler
class Context
{
public:
Context(char const* stream_begin_in, tr_error** error_in)
constexpr Context(char const* stream_begin_in, tr_error** error_in)
: error{ error_in }
, stream_begin_{ stream_begin_in }
{
}
[[nodiscard]] std::pair<long, long> tokenSpan() const
[[nodiscard]] constexpr std::pair<long, long> tokenSpan() const
{
return std::make_pair(token_begin_ - stream_begin_, token_end_ - stream_begin_);
return { token_begin_ - stream_begin_, token_end_ - stream_begin_ };
}
[[nodiscard]] auto raw() const
[[nodiscard]] constexpr auto raw() const
{
return std::string_view{ token_begin_, size_t(token_end_ - token_begin_) };
}
void setTokenSpan(char const* a, size_t len)
constexpr void setTokenSpan(char const* a, size_t len)
{
token_begin_ = a;
token_end_ = token_begin_ + len;
}
tr_error** error = nullptr;
private:

View File

@@ -49,7 +49,7 @@ public:
return is_enabled_;
}
void setEnabled(bool is_enabled) noexcept
constexpr void setEnabled(bool is_enabled) noexcept
{
is_enabled_ = is_enabled;
}

View File

@@ -81,7 +81,7 @@ public:
user_data_ = user_data;
}
void clear_callbacks()
constexpr void clear_callbacks()
{
set_callbacks(nullptr, nullptr, nullptr, nullptr);
}