Skip to content

Commit

Permalink
rpc: avoid copying UniValue keys when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
theuni committed May 13, 2024
1 parent d63cfed commit 9bd23b5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2011,13 +2011,14 @@ static RPCHelpMan getblockstats()
}

UniValue ret(UniValue::VOBJ);
for (const std::string& stat : stats) {
for (auto it = stats.begin(); it != stats.end(); ++it) {
std::string& stat = stats.extract(it).value();
const UniValue& value = ret_all[stat];
if (value.isNull()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid selected statistic '%s'", stat));
}
// TODO
ret.pushKV(stat, value);
ret.pushKV(std::move(stat), value);
}
return ret;
},
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/rpc/addresses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ RPCHelpMan getaddressesbylabel()
// which currently is O(1).
UniValue value(UniValue::VOBJ);
value.pushKV("purpose", _purpose ? PurposeToString(*_purpose) : "unknown");
ret.pushKVEnd(address, std::move(value));
ret.pushKVEnd(std::move(address), std::move(value));
}
});

Expand Down

0 comments on commit 9bd23b5

Please sign in to comment.