From 0344a12b40613c3cdcb227e084ad6a0b840dd55d Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 14 Jul 2019 19:12:46 -0700 Subject: [PATCH] ircd::json: Inline value constructors. --- include/ircd/json/member.h | 1 + include/ircd/json/value.h | 187 +++++++++++++++++++++++++++++++++++++ ircd/json.cc | 165 -------------------------------- 3 files changed, 188 insertions(+), 165 deletions(-) diff --git a/include/ircd/json/member.h b/include/ircd/json/member.h index 0f0df7b39..dc587a571 100644 --- a/include/ircd/json/member.h +++ b/include/ircd/json/member.h @@ -61,6 +61,7 @@ ircd::json::member::member(const string_view &key, {} template +inline __attribute__((always_inline)) ircd::json::member::member(const string_view &key, V&& v) :member diff --git a/include/ircd/json/value.h b/include/ircd/json/value.h index f2de8675b..6e73b544e 100644 --- a/include/ircd/json/value.h +++ b/include/ircd/json/value.h @@ -145,6 +145,193 @@ ircd::json::value::value() ,floats{false} {} +inline +ircd::json::value::value(const nullptr_t &) +:value +{ + literal_null, type::LITERAL +} +{ +} + +inline +ircd::json::value::value(const json::object &sv) +:value{sv, OBJECT} +{ +} + +inline +ircd::json::value::value(const json::array &sv) +:value{sv, ARRAY} +{ +} + +inline +ircd::json::value::value(const bool &boolean) +:value +{ + boolean? literal_true : literal_false, type::LITERAL +} +{ +} + +inline +ircd::json::value::value(const uint8_t &integer) +:value{int64_t{integer}} +{ +} + +inline +ircd::json::value::value(const int8_t &integer) +:value{int64_t{integer}} +{ +} + +inline +ircd::json::value::value(const uint16_t &integer) +:value{int64_t{integer}} +{ +} + +inline +ircd::json::value::value(const int16_t &integer) +:value{int64_t{integer}} +{ +} + +inline +ircd::json::value::value(const uint32_t &integer) +:value{int64_t{integer}} +{ +} + +inline +ircd::json::value::value(const int32_t &integer) +:value{int64_t{integer}} +{ +} + +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(const char *const &str) +:value{string_view{str}} +{ +} + +inline +ircd::json::value::value(const char *const &str, + const enum type &type) +:value{string_view{str}, type} +{ +} + +inline +ircd::json::value::value(const string_view &sv) +:value{sv, json::type(sv, strict, std::nothrow)} +{ +} + +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) +:value{s, json::type(s, strict, std::nothrow)} +{ +} + +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 &&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 &&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(value &&other) +noexcept +:integer{other.integer} +,len{other.len} +,type{other.type} +,serial{other.serial} +,alloc{other.alloc} +,floats{other.floats} +{ + other.alloc = false; +} + template ircd::json::value::value(const char (&str)[N]) :value{string_view{str, strnlen(str, N)}} diff --git a/ircd/json.cc b/ircd/json.cc index 28e844f05..15e370fda 100644 --- a/ircd/json.cc +++ b/ircd/json.cc @@ -3403,114 +3403,6 @@ ircd::json::type(const value &a) // value::value // -ircd::json::value::value(const nullptr_t &) -:value -{ - literal_null, type::LITERAL -} -{ -} - -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 bool &boolean) -:value -{ - boolean? literal_true : literal_false, type::LITERAL -} -{ -} - -ircd::json::value::value(const uint8_t &integer) -:value{int64_t{integer}} -{ -} - -ircd::json::value::value(const int8_t &integer) -:value{int64_t{integer}} -{ -} - -ircd::json::value::value(const uint16_t &integer) -:value{int64_t{integer}} -{ -} - -ircd::json::value::value(const int16_t &integer) -:value{int64_t{integer}} -{ -} - -ircd::json::value::value(const uint32_t &integer) -:value{int64_t{integer}} -{ -} - -ircd::json::value::value(const int32_t &integer) -:value{int64_t{integer}} -{ -} - -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 char *const &str) -:value{string_view{str}} -{ -} - -ircd::json::value::value(const char *const &str, - const enum type &type) -:value{string_view{str}, type} -{ -} - -ircd::json::value::value(const string_view &sv) -:value{sv, json::type(sv, strict, std::nothrow)} -{ -} - -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) -:value{s, json::type(s, strict, std::nothrow)} -{ -} - ircd::json::value::value(const std::string &s, const enum type &type) :string{nullptr} @@ -3528,51 +3420,6 @@ ircd::json::value::value(const std::string &s, }); } -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 &&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 &&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 json::members &members) :string{nullptr} ,len{serialized(members)} @@ -3653,18 +3500,6 @@ 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