mirror of
https://github.com/matrix-construct/construct
synced 2024-10-31 19:08:59 +01:00
ircd: Apply noexcept on various constexpr callstacks.
This commit is contained in:
parent
7fb0958080
commit
a8b3e29cac
7 changed files with 52 additions and 19 deletions
|
@ -18,6 +18,7 @@ template<size_t hash,
|
|||
class tuple>
|
||||
enable_if_tuple<tuple, const tuple_value_type<tuple, indexof<tuple, hash>()> &>
|
||||
get(const tuple &t)
|
||||
noexcept
|
||||
{
|
||||
constexpr size_t idx
|
||||
{
|
||||
|
@ -37,6 +38,7 @@ template<size_t hash,
|
|||
enable_if_tuple<tuple, tuple_value_type<tuple, indexof<tuple, hash>()>>
|
||||
get(const tuple &t,
|
||||
const tuple_value_type<tuple, indexof<tuple, hash>()> &def)
|
||||
noexcept
|
||||
{
|
||||
constexpr size_t idx
|
||||
{
|
||||
|
@ -55,6 +57,7 @@ template<size_t hash,
|
|||
class tuple>
|
||||
enable_if_tuple<tuple, tuple_value_type<tuple, indexof<tuple, hash>()> &>
|
||||
get(tuple &t)
|
||||
noexcept
|
||||
{
|
||||
constexpr size_t idx
|
||||
{
|
||||
|
@ -74,6 +77,7 @@ template<size_t hash,
|
|||
enable_if_tuple<tuple, tuple_value_type<tuple, indexof<tuple, hash>()> &>
|
||||
get(tuple &t,
|
||||
tuple_value_type<tuple, indexof<tuple, hash>()> &def)
|
||||
noexcept
|
||||
{
|
||||
auto &ret
|
||||
{
|
||||
|
@ -87,6 +91,7 @@ template<const char *const &name,
|
|||
class tuple>
|
||||
enable_if_tuple<tuple, const tuple_value_type<tuple, indexof<tuple, name>()> &>
|
||||
get(const tuple &t)
|
||||
noexcept
|
||||
{
|
||||
return get<name_hash(name), tuple>(t);
|
||||
}
|
||||
|
@ -96,6 +101,7 @@ template<const char *const &name,
|
|||
enable_if_tuple<tuple, tuple_value_type<tuple, indexof<tuple, name>()>>
|
||||
get(const tuple &t,
|
||||
const tuple_value_type<tuple, indexof<tuple, name>()> &def)
|
||||
noexcept
|
||||
{
|
||||
return get<name_hash(name), tuple>(t, def);
|
||||
}
|
||||
|
@ -104,6 +110,7 @@ template<const char *const &name,
|
|||
class tuple>
|
||||
enable_if_tuple<tuple, tuple_value_type<tuple, indexof<tuple, name>()>>
|
||||
get(tuple &t)
|
||||
noexcept
|
||||
{
|
||||
return get<name_hash(name), tuple>(t);
|
||||
}
|
||||
|
@ -113,6 +120,7 @@ template<const char *const &name,
|
|||
enable_if_tuple<tuple, tuple_value_type<tuple, indexof<tuple, name>()>>
|
||||
get(tuple &t,
|
||||
tuple_value_type<tuple, indexof<tuple, hash>()> &def)
|
||||
noexcept
|
||||
{
|
||||
return get<name_hash(name), tuple>(t, def);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ template<class tuple,
|
|||
size_t i>
|
||||
constexpr typename std::enable_if<i == size<tuple>(), size_t>::type
|
||||
indexof()
|
||||
noexcept
|
||||
{
|
||||
return size<tuple>();
|
||||
}
|
||||
|
@ -28,6 +29,7 @@ template<class tuple,
|
|||
size_t i = 0>
|
||||
constexpr typename std::enable_if<i < size<tuple>(), size_t>::type
|
||||
indexof()
|
||||
noexcept
|
||||
{
|
||||
constexpr auto equal
|
||||
{
|
||||
|
@ -42,6 +44,7 @@ template<class tuple,
|
|||
size_t i>
|
||||
constexpr typename std::enable_if<i == size<tuple>(), size_t>::type
|
||||
indexof()
|
||||
noexcept
|
||||
{
|
||||
return size<tuple>();
|
||||
}
|
||||
|
@ -51,6 +54,7 @@ template<class tuple,
|
|||
size_t i = 0>
|
||||
constexpr typename std::enable_if<i < size<tuple>(), size_t>::type
|
||||
indexof()
|
||||
noexcept
|
||||
{
|
||||
return indexof<tuple, name_hash(name)>();
|
||||
}
|
||||
|
@ -59,6 +63,7 @@ template<class tuple,
|
|||
size_t i>
|
||||
constexpr typename std::enable_if<i == size<tuple>(), size_t>::type
|
||||
indexof(const char *const &name)
|
||||
noexcept
|
||||
{
|
||||
return size<tuple>();
|
||||
}
|
||||
|
@ -67,6 +72,7 @@ template<class tuple,
|
|||
size_t i = 0>
|
||||
constexpr typename std::enable_if<i < size<tuple>(), size_t>::type
|
||||
indexof(const char *const &name)
|
||||
noexcept
|
||||
{
|
||||
constexpr auto equal
|
||||
{
|
||||
|
@ -80,6 +86,7 @@ template<class tuple,
|
|||
size_t i>
|
||||
constexpr typename std::enable_if<i == size<tuple>(), size_t>::type
|
||||
indexof(const string_view &name)
|
||||
noexcept
|
||||
{
|
||||
return size<tuple>();
|
||||
}
|
||||
|
@ -88,6 +95,7 @@ template<class tuple,
|
|||
size_t i = 0>
|
||||
constexpr typename std::enable_if<i < size<tuple>(), size_t>::type
|
||||
indexof(const string_view &name)
|
||||
noexcept
|
||||
{
|
||||
const auto equal
|
||||
{
|
||||
|
|
|
@ -18,6 +18,7 @@ template<class tuple,
|
|||
size_t i>
|
||||
constexpr enable_if_tuple<tuple, const char *>
|
||||
key()
|
||||
noexcept
|
||||
{
|
||||
return tuple_element<tuple, i>::key;
|
||||
}
|
||||
|
@ -26,6 +27,7 @@ template<class tuple,
|
|||
size_t i>
|
||||
constexpr typename std::enable_if<i == tuple::size(), const char *>::type
|
||||
key(const size_t &j)
|
||||
noexcept
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -34,6 +36,7 @@ template<class tuple,
|
|||
size_t i = 0>
|
||||
constexpr typename std::enable_if<i < tuple::size(), const char *>::type
|
||||
key(const size_t &j)
|
||||
noexcept
|
||||
{
|
||||
return j == i?
|
||||
tuple_element<tuple, i>::key:
|
||||
|
@ -44,6 +47,7 @@ template<size_t i,
|
|||
class tuple>
|
||||
enable_if_tuple<tuple, const char *>
|
||||
key(const tuple &t)
|
||||
noexcept
|
||||
{
|
||||
return std::get<i>(t).key;
|
||||
}
|
||||
|
|
|
@ -57,13 +57,13 @@ struct tuple
|
|||
using tuple_type = std::tuple<T...>;
|
||||
using super_type = tuple<T...>;
|
||||
|
||||
static constexpr size_t size();
|
||||
static constexpr size_t size() noexcept;
|
||||
|
||||
operator json::value() const;
|
||||
operator crh::sha256::buf() const;
|
||||
|
||||
template<class name> constexpr decltype(auto) get(name&&) const;
|
||||
template<class name> constexpr decltype(auto) get(name&&);
|
||||
template<class name> constexpr decltype(auto) get(name&&) const noexcept;
|
||||
template<class name> constexpr decltype(auto) get(name&&) noexcept;
|
||||
template<class name> constexpr decltype(auto) at(name&&) const;
|
||||
template<class name> constexpr decltype(auto) at(name&&);
|
||||
|
||||
|
@ -79,6 +79,7 @@ struct tuple
|
|||
template<class tuple>
|
||||
constexpr bool
|
||||
is_tuple()
|
||||
noexcept
|
||||
{
|
||||
return std::is_base_of<tuple_base, tuple>::value;
|
||||
}
|
||||
|
@ -123,6 +124,7 @@ stdcast(tuple &o)
|
|||
template<class tuple>
|
||||
constexpr enable_if_tuple<tuple, size_t>
|
||||
size()
|
||||
noexcept
|
||||
{
|
||||
return tuple_size<tuple>::value;
|
||||
}
|
||||
|
@ -140,6 +142,7 @@ template<size_t i,
|
|||
class tuple>
|
||||
enable_if_tuple<tuple, tuple_value_type<tuple, i> &>
|
||||
val(tuple &t)
|
||||
noexcept
|
||||
{
|
||||
return static_cast<tuple_value_type<tuple, i> &>(std::get<i>(t));
|
||||
}
|
||||
|
@ -148,6 +151,7 @@ template<size_t i,
|
|||
class tuple>
|
||||
enable_if_tuple<tuple, const tuple_value_type<tuple, i> &>
|
||||
val(const tuple &t)
|
||||
noexcept
|
||||
{
|
||||
return static_cast<const tuple_value_type<tuple, i> &>(std::get<i>(t));
|
||||
}
|
||||
|
@ -269,6 +273,7 @@ template<class... T>
|
|||
template<class name>
|
||||
constexpr decltype(auto)
|
||||
tuple<T...>::get(name&& n)
|
||||
noexcept
|
||||
{
|
||||
constexpr const size_t hash
|
||||
{
|
||||
|
@ -282,7 +287,7 @@ template<class... T>
|
|||
template<class name>
|
||||
constexpr decltype(auto)
|
||||
tuple<T...>::get(name&& n)
|
||||
const
|
||||
const noexcept
|
||||
{
|
||||
constexpr const size_t hash
|
||||
{
|
||||
|
@ -295,6 +300,7 @@ const
|
|||
template<class... T>
|
||||
constexpr size_t
|
||||
tuple<T...>::size()
|
||||
noexcept
|
||||
{
|
||||
return std::tuple_size<tuple_type>();
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@ namespace ircd::json
|
|||
template<size_t SIZE> struct buffer;
|
||||
|
||||
using name_hash_t = size_t;
|
||||
constexpr name_hash_t name_hash(const string_view name);
|
||||
constexpr name_hash_t operator ""_(const char *const name, const size_t len);
|
||||
constexpr name_hash_t name_hash(const string_view name) noexcept;
|
||||
constexpr name_hash_t operator ""_(const char *const name, const size_t len) noexcept;
|
||||
|
||||
size_t serialized(const string_view &);
|
||||
string_view stringify(mutable_buffer &, const string_view &);
|
||||
|
@ -79,12 +79,14 @@ ircd::json::print(const mutable_buffer &buf,
|
|||
|
||||
constexpr ircd::json::name_hash_t
|
||||
ircd::json::operator ""_(const char *const text, const size_t len)
|
||||
noexcept
|
||||
{
|
||||
return name_hash(string_view(text, len));
|
||||
}
|
||||
|
||||
constexpr ircd::json::name_hash_t
|
||||
ircd::json::name_hash(const string_view name)
|
||||
noexcept
|
||||
{
|
||||
return ircd::hash(name);
|
||||
}
|
||||
|
|
|
@ -15,9 +15,9 @@ namespace ircd
|
|||
{
|
||||
struct string_view;
|
||||
|
||||
constexpr size_t _constexpr_strlen(const char *);
|
||||
constexpr const char *data(const string_view &);
|
||||
constexpr size_t size(const string_view &);
|
||||
constexpr size_t _constexpr_strlen(const char *) noexcept;
|
||||
constexpr const char *data(const string_view &) noexcept;
|
||||
constexpr size_t size(const string_view &) noexcept;
|
||||
bool empty(const string_view &);
|
||||
bool operator!(const string_view &);
|
||||
bool defined(const string_view &);
|
||||
|
@ -144,7 +144,7 @@ struct ircd::string_view
|
|||
}
|
||||
|
||||
// (non-standard) our iterator-based constructor
|
||||
constexpr string_view(const char *const &begin, const char *const &end)
|
||||
constexpr string_view(const char *const &begin, const char *const &end) noexcept
|
||||
:string_view{begin, size_t(end - begin)}
|
||||
{
|
||||
assert(begin <= end);
|
||||
|
@ -158,7 +158,7 @@ struct ircd::string_view
|
|||
// (non-standard) our array based constructor
|
||||
template<size_t SIZE> constexpr
|
||||
__attribute__((always_inline))
|
||||
string_view(const std::array<char, SIZE> &array)
|
||||
string_view(const std::array<char, SIZE> &array) noexcept
|
||||
:string_view
|
||||
{
|
||||
array.data(), std::find(array.begin(), array.end(), '\0')
|
||||
|
@ -167,22 +167,21 @@ struct ircd::string_view
|
|||
// (non-standard) our buffer based constructor
|
||||
template<size_t SIZE> constexpr
|
||||
__attribute__((always_inline))
|
||||
string_view(const char (&buf)[SIZE])
|
||||
string_view(const char (&buf)[SIZE]) noexcept
|
||||
:string_view
|
||||
{
|
||||
buf, std::find(buf, buf + SIZE, '\0')
|
||||
}{}
|
||||
|
||||
constexpr string_view(const char *const &start, const size_t &size)
|
||||
constexpr string_view(const char *const &start, const size_t &size) noexcept
|
||||
:std::string_view{start, size}
|
||||
{}
|
||||
|
||||
constexpr string_view(const char *const &start)
|
||||
constexpr string_view(const char *const &start) noexcept
|
||||
:std::string_view{start, _constexpr_strlen(start)}
|
||||
{}
|
||||
|
||||
string_view(const std::string &string)
|
||||
noexcept
|
||||
string_view(const std::string &string) noexcept
|
||||
:string_view{string.data(), string.size()}
|
||||
{}
|
||||
|
||||
|
@ -257,12 +256,14 @@ ircd::defined(const string_view &str)
|
|||
|
||||
constexpr size_t
|
||||
ircd::size(const string_view &str)
|
||||
noexcept
|
||||
{
|
||||
return str.size();
|
||||
}
|
||||
|
||||
constexpr const char *
|
||||
ircd::data(const string_view &str)
|
||||
noexcept
|
||||
{
|
||||
return str.data();
|
||||
}
|
||||
|
@ -270,6 +271,7 @@ ircd::data(const string_view &str)
|
|||
[[gnu::pure]]
|
||||
constexpr size_t
|
||||
ircd::_constexpr_strlen(const char *const s)
|
||||
noexcept
|
||||
{
|
||||
const char *e(s);
|
||||
if(e) for(; *e; ++e);
|
||||
|
|
|
@ -17,12 +17,12 @@ inline namespace util
|
|||
// constexpr bernstein string hasher suite; these functions will hash the
|
||||
// string at compile time leaving an integer residue at runtime. Decent
|
||||
// primes are at least 7681 and 5381.
|
||||
template<size_t PRIME = 7681> constexpr size_t hash(const char16_t *const str, const size_t i = 0);
|
||||
template<size_t PRIME = 7681> constexpr size_t hash(const string_view str, const size_t i = 0);
|
||||
template<size_t PRIME = 7681> constexpr size_t hash(const char16_t *const str, const size_t i = 0) noexcept;
|
||||
template<size_t PRIME = 7681> constexpr size_t hash(const string_view str, const size_t i = 0) noexcept;
|
||||
|
||||
// Note that at runtime this hash uses multiplication on every character
|
||||
// which can consume many cycles...
|
||||
template<size_t PRIME = 7681> size_t hash(const std::u16string &str, const size_t i = 0);
|
||||
template<size_t PRIME = 7681> size_t hash(const std::u16string &str, const size_t i = 0) noexcept;
|
||||
}}
|
||||
|
||||
/// Runtime hashing of a std::u16string (for js). Non-cryptographic.
|
||||
|
@ -31,6 +31,7 @@ template<size_t PRIME>
|
|||
size_t
|
||||
ircd::util::hash(const std::u16string &str,
|
||||
const size_t i)
|
||||
noexcept
|
||||
{
|
||||
return i >= str.size()? PRIME : (hash(str, i+1) * 33ULL) ^ str.at(i);
|
||||
}
|
||||
|
@ -41,6 +42,7 @@ template<size_t PRIME>
|
|||
constexpr size_t
|
||||
ircd::util::hash(const string_view str,
|
||||
const size_t i)
|
||||
noexcept
|
||||
{
|
||||
return i >= str.size()? PRIME : (hash(str, i+1) * 33ULL) ^ str.at(i);
|
||||
}
|
||||
|
@ -51,6 +53,7 @@ template<size_t PRIME>
|
|||
constexpr size_t
|
||||
ircd::util::hash(const char16_t *const str,
|
||||
const size_t i)
|
||||
noexcept
|
||||
{
|
||||
return !str[i]? PRIME : (hash(str, i+1) * 33ULL) ^ str[i];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue