0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

ircd::json: Deinline various value related.

This commit is contained in:
Jason Volk 2018-04-04 15:20:24 -07:00
parent bf4da27fc6
commit 93316f4692
2 changed files with 183 additions and 198 deletions

View file

@ -137,64 +137,6 @@ ircd::json::value::value()
,floats{false}
{}
inline
ircd::json::value::value(const string_view &sv,
const enum type &type)
:string{sv.data()}
,len{sv.size()}
,type{type}
,serial{type == STRING? surrounds(sv, '"') : true}
,alloc{false}
,floats{false}
{}
inline
ircd::json::value::value(const std::string &s,
const enum type &type)
:string{nullptr}
,len{0}
,type{type}
,serial{type == STRING? surrounds(s, '"') : true}
,alloc{true}
,floats{false}
{
create_string(s.size(), [&s](const mutable_buffer &buf)
{
copy(buf, string_view{s});
});
}
inline
ircd::json::value::value(const char *const &str,
const enum type &type)
:value{string_view{str}, type}
{}
inline
ircd::json::value::value(const char *const &str)
:value{string_view{str}}
{}
inline
ircd::json::value::value(const string_view &sv)
:value{sv, json::type(sv, std::nothrow)}
{}
inline
ircd::json::value::value(const std::string &s)
:value{s, json::type(s, std::nothrow)}
{}
inline
ircd::json::value::value(const json::object &sv)
:value{sv, OBJECT}
{}
inline
ircd::json::value::value(const json::array &sv)
:value{sv, ARRAY}
{}
template<size_t N>
ircd::json::value::value(const char (&str)[N])
:value{string_view{str, strnlen(str, N)}}
@ -205,142 +147,3 @@ ircd::json::value::value(const char (&str)[N],
const enum type &type)
:value{string_view{str, strnlen(str, N)}, type}
{}
inline
ircd::json::value::value(const nullptr_t &)
:value
{
literal_null, type::LITERAL
}{}
inline
ircd::json::value::value(const bool &boolean)
:value
{
boolean? literal_true : literal_false, type::LITERAL
}{}
inline
ircd::json::value::value(const struct value *const &array,
const size_t &len)
:array{array}
,len{len}
,type{ARRAY}
,serial{false}
,alloc{false}
,floats{false}
{
}
inline
ircd::json::value::value(std::unique_ptr<const struct value[]> &&array,
const size_t &len)
:array{array.get()}
,len{len}
,type{ARRAY}
,serial{false}
,alloc{true}
,floats{false}
{
array.release();
}
inline
ircd::json::value::value(const struct member *const &object,
const size_t &len)
:object{object}
,len{len}
,type{OBJECT}
,serial{false}
,alloc{false}
,floats{false}
{}
inline
ircd::json::value::value(std::unique_ptr<const struct member[]> &&object,
const size_t &len)
:object{object.get()}
,len{len}
,type{OBJECT}
,serial{false}
,alloc{true}
,floats{false}
{
object.release();
}
inline
ircd::json::value::value(const int64_t &integer)
:integer{integer}
,len{0}
,type{NUMBER}
,serial{false}
,alloc{false}
,floats{false}
{}
inline
ircd::json::value::value(const double &floating)
:floating{floating}
,len{0}
,type{NUMBER}
,serial{false}
,alloc{false}
,floats{true}
{}
inline
ircd::json::value::value(value &&other)
noexcept
:integer{other.integer}
,len{other.len}
,type{other.type}
,serial{other.serial}
,alloc{other.alloc}
,floats{other.floats}
{
other.alloc = false;
}
inline ircd::json::value &
ircd::json::value::operator=(value &&other)
noexcept
{
this->~value();
integer = other.integer;
len = other.len;
type = other.type;
serial = other.serial;
alloc = other.alloc;
other.alloc = false;
floats = other.floats;
return *this;
}
inline bool
ircd::json::defined(const value &a)
{
return !a.undefined();
}
inline enum ircd::json::type
ircd::json::type(const value &a)
{
return a.type;
}
inline size_t
ircd::json::serialized(const bool &b)
{
constexpr const size_t t
{
strlen("true")
};
constexpr const size_t f
{
strlen("false")
};
return b? t : f;
}

View file

@ -1772,10 +1772,165 @@ ircd::json::serialized(const value &v)
throw type_error("deciding the size of a type[%u] is undefined", int(v.type));
}
size_t
ircd::json::serialized(const bool &b)
{
constexpr const size_t t
{
strlen("true")
};
constexpr const size_t f
{
strlen("false")
};
return b? t : f;
}
bool
ircd::json::defined(const value &a)
{
return !a.undefined();
}
enum ircd::json::type
ircd::json::type(const value &a)
{
return a.type;
}
//
// json::value
// value::value
//
ircd::json::value::value(const string_view &sv,
const enum type &type)
:string{sv.data()}
,len{sv.size()}
,type{type}
,serial{type == STRING? surrounds(sv, '"') : true}
,alloc{false}
,floats{false}
{}
ircd::json::value::value(const std::string &s,
const enum type &type)
:string{nullptr}
,len{0}
,type{type}
,serial{type == STRING? surrounds(s, '"') : true}
,alloc{true}
,floats{false}
{
const string_view sv{s};
create_string(serialized(sv), [&sv]
(mutable_buffer buf)
{
json::stringify(buf, sv);
});
}
ircd::json::value::value(const char *const &str,
const enum type &type)
:value{string_view{str}, type}
{}
ircd::json::value::value(const char *const &str)
:value{string_view{str}}
{}
ircd::json::value::value(const string_view &sv)
:value{sv, json::type(sv, std::nothrow)}
{}
ircd::json::value::value(const std::string &s)
:value{s, json::type(s, std::nothrow)}
{}
ircd::json::value::value(const json::object &sv)
:value{sv, OBJECT}
{}
ircd::json::value::value(const json::array &sv)
:value{sv, ARRAY}
{}
ircd::json::value::value(const nullptr_t &)
:value
{
literal_null, type::LITERAL
}{}
ircd::json::value::value(const bool &boolean)
:value
{
boolean? literal_true : literal_false, type::LITERAL
}{}
ircd::json::value::value(const struct value *const &array,
const size_t &len)
:array{array}
,len{len}
,type{ARRAY}
,serial{false}
,alloc{false}
,floats{false}
{
}
ircd::json::value::value(std::unique_ptr<const struct value[]> &&array,
const size_t &len)
:array{array.get()}
,len{len}
,type{ARRAY}
,serial{false}
,alloc{true}
,floats{false}
{
array.release();
}
ircd::json::value::value(const struct member *const &object,
const size_t &len)
:object{object}
,len{len}
,type{OBJECT}
,serial{false}
,alloc{false}
,floats{false}
{}
ircd::json::value::value(std::unique_ptr<const struct member[]> &&object,
const size_t &len)
:object{object.get()}
,len{len}
,type{OBJECT}
,serial{false}
,alloc{true}
,floats{false}
{
object.release();
}
ircd::json::value::value(const int64_t &integer)
:integer{integer}
,len{0}
,type{NUMBER}
,serial{false}
,alloc{false}
,floats{false}
{}
ircd::json::value::value(const double &floating)
:floating{floating}
,len{0}
,type{NUMBER}
,serial{false}
,alloc{false}
,floats{true}
{}
ircd::json::value::value(const json::members &members)
:string{nullptr}
,len{serialized(members)}
@ -1856,6 +2011,33 @@ ircd::json::value::value(const value &other)
}
}
ircd::json::value::value(value &&other)
noexcept
:integer{other.integer}
,len{other.len}
,type{other.type}
,serial{other.serial}
,alloc{other.alloc}
,floats{other.floats}
{
other.alloc = false;
}
ircd::json::value &
ircd::json::value::operator=(value &&other)
noexcept
{
this->~value();
integer = other.integer;
len = other.len;
type = other.type;
serial = other.serial;
alloc = other.alloc;
other.alloc = false;
floats = other.floats;
return *this;
}
ircd::json::value &
ircd::json::value::operator=(const value &other)
{