mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 07:20:55 +01:00
ircd::json: Use consumption protocol for create_string closure.
This commit is contained in:
parent
0e526484ea
commit
42a22a6c79
2 changed files with 9 additions and 8 deletions
|
@ -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:
|
||||
|
|
15
ircd/json.cc
15
ircd/json.cc
|
@ -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
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue