mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-24 22:45:41 +01:00
rpc: Avoid copies in JSONRPCReplyObj()
Change parameters from const references to values, so they can be moved into the reply instead of copied. Also update callers to move instead of copy.
This commit is contained in:
committed by
Ryan Ofsky
parent
09416f9ec4
commit
df6e3756d6
@@ -37,24 +37,18 @@ UniValue JSONRPCRequestObj(const std::string& strMethod, const UniValue& params,
|
||||
return request;
|
||||
}
|
||||
|
||||
UniValue JSONRPCReplyObj(const UniValue& result, const UniValue& error, const UniValue& id)
|
||||
UniValue JSONRPCReplyObj(UniValue result, UniValue error, UniValue id)
|
||||
{
|
||||
UniValue reply(UniValue::VOBJ);
|
||||
if (!error.isNull())
|
||||
reply.pushKV("result", NullUniValue);
|
||||
else
|
||||
reply.pushKV("result", result);
|
||||
reply.pushKV("error", error);
|
||||
reply.pushKV("id", id);
|
||||
reply.pushKV("result", std::move(result));
|
||||
reply.pushKV("error", std::move(error));
|
||||
reply.pushKV("id", std::move(id));
|
||||
return reply;
|
||||
}
|
||||
|
||||
std::string JSONRPCReply(const UniValue& result, const UniValue& error, const UniValue& id)
|
||||
{
|
||||
UniValue reply = JSONRPCReplyObj(result, error, id);
|
||||
return reply.write() + "\n";
|
||||
}
|
||||
|
||||
UniValue JSONRPCError(int code, const std::string& message)
|
||||
{
|
||||
UniValue error(UniValue::VOBJ);
|
||||
|
||||
Reference in New Issue
Block a user