0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd::json: Eliminate output validation for release builds.

This commit is contained in:
Jason Volk 2020-05-21 09:17:13 -07:00
parent c73636f950
commit 54a72532b6
3 changed files with 16 additions and 6 deletions

View file

@ -65,6 +65,6 @@ ircd::json::stringify(const mutable_buffer &&mb_,
{
mutable_buffer mb(mb_);
const auto ret(stringify(mb, std::forward<T>(t)...));
valid_output(ret, serialized(std::forward<T>(t))...);
debug_valid_output(ret, serialized(std::forward<T>(t)...));
return ret;
}

View file

@ -59,7 +59,7 @@ ircd::json::strung::strung(T&&... t)
stringify(mutable_buffer{out}, std::forward<T>(t)...)
};
valid_output(sv, ircd::size(out));
debug_valid_output(sv, ircd::size(out));
return sv;
})
}

View file

@ -24,6 +24,9 @@ namespace ircd::json
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;
void valid_output(const string_view &, const size_t &expected);
void debug_valid_output(const string_view &, const size_t &expected);
size_t serialized(const string_view &);
string_view stringify(mutable_buffer &, const string_view &);
template<class... T> size_t print(const mutable_buffer &buf, T&&... t);
@ -32,9 +35,6 @@ namespace ircd::json
bool valid(const string_view &, std::nothrow_t) noexcept;
void valid(const string_view &);
std::string why(const string_view &);
// (Internal) validates output
void valid_output(const string_view &, const size_t &expected);
}
/// Alternative to `json::strung` which uses a fixed array rather than an
@ -73,10 +73,20 @@ ircd::json::print(const mutable_buffer &buf,
};
buf[sv.size()] = '\0';
valid_output(sv, size(sv)); // no size expectation check
debug_valid_output(sv, size(sv)); // no size expectation check
return sv.size();
}
extern inline void
__attribute__((always_inline, gnu_inline, artificial))
ircd::json::debug_valid_output(const string_view &in,
const size_t &expected)
{
#ifdef RB_DEBUG
valid_output(in, expected);
#endif
}
constexpr ircd::json::name_hash_t
ircd::json::operator ""_(const char *const text, const size_t len)
noexcept