diff options
author | Matthew Zipkin <pinheadmz@gmail.com> | 2024-01-23 10:33:26 -0500 |
---|---|---|
committer | Ryan Ofsky <ryan@ofsky.org> | 2024-03-07 19:13:15 -0500 |
commit | df6e3756d6feaf1856e7886820b70874209fd90b (patch) | |
tree | e2645fd3585367a5169e07deadbff7d8d3f9e375 /src/rpc | |
parent | 09416f9ec445e4d6bb277400758083b0b4e8b174 (diff) | |
download | bitcoin-df6e3756d6feaf1856e7886820b70874209fd90b.tar.xz |
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.
Diffstat (limited to 'src/rpc')
-rw-r--r-- | src/rpc/request.cpp | 14 | ||||
-rw-r--r-- | src/rpc/request.h | 3 | ||||
-rw-r--r-- | src/rpc/server.cpp | 6 |
3 files changed, 8 insertions, 15 deletions
diff --git a/src/rpc/request.cpp b/src/rpc/request.cpp index b7acd62ee3..12726ecc88 100644 --- a/src/rpc/request.cpp +++ b/src/rpc/request.cpp @@ -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); diff --git a/src/rpc/request.h b/src/rpc/request.h index a682c58d96..116ebb8aac 100644 --- a/src/rpc/request.h +++ b/src/rpc/request.h @@ -12,8 +12,7 @@ #include <univalue.h> UniValue JSONRPCRequestObj(const std::string& strMethod, const UniValue& params, const UniValue& id); -UniValue JSONRPCReplyObj(const UniValue& result, const UniValue& error, const UniValue& id); -std::string JSONRPCReply(const UniValue& result, const UniValue& error, const UniValue& id); +UniValue JSONRPCReplyObj(UniValue result, UniValue error, UniValue id); UniValue JSONRPCError(int code, const std::string& message); /** Generate a new RPC authentication cookie and write it to disk */ diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 4883341522..fd18a7f9ec 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -366,11 +366,11 @@ static UniValue JSONRPCExecOne(JSONRPCRequest jreq, const UniValue& req) jreq.parse(req); UniValue result = tableRPC.execute(jreq); - rpc_result = JSONRPCReplyObj(result, NullUniValue, jreq.id); + rpc_result = JSONRPCReplyObj(std::move(result), NullUniValue, jreq.id); } - catch (const UniValue& objError) + catch (UniValue& e) { - rpc_result = JSONRPCReplyObj(NullUniValue, objError, jreq.id); + rpc_result = JSONRPCReplyObj(NullUniValue, std::move(e), jreq.id); } catch (const std::exception& e) { |