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

ircd::json: Use consumption protocol for create_string closure.

This commit is contained in:
Jason Volk 2018-02-18 14:04:22 -08:00
parent 0e526484ea
commit 42a22a6c79
2 changed files with 9 additions and 8 deletions

View file

@ -71,7 +71,7 @@ struct ircd::json::value
uint64_t alloc : 1; ///< indicates the pointer for type is owned
uint64_t floats : 1; ///< for NUMBER type, integer or floating
using create_string_closure = std::function<void (const mutable_buffer &)>;
using create_string_closure = std::function<void (mutable_buffer &)>;
void create_string(const size_t &len, const create_string_closure &);
public:

View file

@ -1198,7 +1198,7 @@ ircd::json::value::value(const json::members &members)
,floats{false}
{
create_string(len, [&members]
(mutable_buffer buffer)
(mutable_buffer &buffer)
{
json::stringify(buffer, members);
});
@ -1214,9 +1214,10 @@ ircd::json::value::value(const value &other)
{
if(alloc && serial)
{
create_string(len, [this](mutable_buffer buffer)
create_string(len, [this]
(mutable_buffer &buffer)
{
copy(buffer, string_view{*this});
consume(buffer, copy(buffer, string_view{*this}));
});
}
else switch(type)
@ -1228,7 +1229,7 @@ ircd::json::value::value(const value &other)
const size_t count(this->len);
create_string(serialized(object, object + count), [this, &count]
(mutable_buffer buffer)
(mutable_buffer &buffer)
{
json::stringify(buffer, object, object + count);
});
@ -1242,7 +1243,7 @@ ircd::json::value::value(const value &other)
const size_t count(this->len);
create_string(serialized(array, array + count), [this, &count]
(mutable_buffer buffer)
(mutable_buffer &buffer)
{
json::stringify(buffer, array, array + count);
});
@ -1255,7 +1256,7 @@ ircd::json::value::value(const value &other)
break;
create_string(serialized(*this), [this]
(mutable_buffer buffer)
(mutable_buffer &buffer)
{
json::stringify(buffer, *this);
});
@ -1516,7 +1517,7 @@ ircd::json::value::create_string(const size_t &len,
new char[max]
};
const mutable_buffer buffer
mutable_buffer buffer
{
string.get(), len
};