rpc: avoid copying into UniValue

These are simple (and hopefully obviously correct) copies that can be moves
instead.
This commit is contained in:
Cory Fields
2024-05-13 20:20:10 +00:00
parent ecd23656db
commit d7707d9843
27 changed files with 183 additions and 183 deletions

View File

@@ -263,7 +263,7 @@ static RPCHelpMan getpeerinfo()
for (const int height : statestats.vHeightInFlight) {
heights.push_back(height);
}
obj.pushKV("inflight", heights);
obj.pushKV("inflight", std::move(heights));
obj.pushKV("addr_relay_enabled", statestats.m_addr_relay_enabled);
obj.pushKV("addr_processed", statestats.m_addr_processed);
obj.pushKV("addr_rate_limited", statestats.m_addr_rate_limited);
@@ -271,7 +271,7 @@ static RPCHelpMan getpeerinfo()
for (const auto& permission : NetPermissions::ToStrings(stats.m_permission_flags)) {
permissions.push_back(permission);
}
obj.pushKV("permissions", permissions);
obj.pushKV("permissions", std::move(permissions));
obj.pushKV("minfeefilter", ValueFromAmount(statestats.m_fee_filter_received));
UniValue sendPerMsgType(UniValue::VOBJ);
@@ -279,19 +279,19 @@ static RPCHelpMan getpeerinfo()
if (i.second > 0)
sendPerMsgType.pushKV(i.first, i.second);
}
obj.pushKV("bytessent_per_msg", sendPerMsgType);
obj.pushKV("bytessent_per_msg", std::move(sendPerMsgType));
UniValue recvPerMsgType(UniValue::VOBJ);
for (const auto& i : stats.mapRecvBytesPerMsgType) {
if (i.second > 0)
recvPerMsgType.pushKV(i.first, i.second);
}
obj.pushKV("bytesrecv_per_msg", recvPerMsgType);
obj.pushKV("bytesrecv_per_msg", std::move(recvPerMsgType));
obj.pushKV("connection_type", ConnectionTypeAsString(stats.m_conn_type));
obj.pushKV("transport_protocol_type", TransportTypeAsString(stats.m_transport_type));
obj.pushKV("session_id", stats.m_session_id);
ret.push_back(obj);
ret.push_back(std::move(obj));
}
return ret;
@@ -532,10 +532,10 @@ static RPCHelpMan getaddednodeinfo()
UniValue address(UniValue::VOBJ);
address.pushKV("address", info.resolvedAddress.ToStringAddrPort());
address.pushKV("connected", info.fInbound ? "inbound" : "outbound");
addresses.push_back(address);
addresses.push_back(std::move(address));
}
obj.pushKV("addresses", addresses);
ret.push_back(obj);
obj.pushKV("addresses", std::move(addresses));
ret.push_back(std::move(obj));
}
return ret;
@@ -587,7 +587,7 @@ static RPCHelpMan getnettotals()
outboundLimit.pushKV("serve_historical_blocks", !connman.OutboundTargetReached(true));
outboundLimit.pushKV("bytes_left_in_cycle", connman.GetOutboundTargetBytesLeft());
outboundLimit.pushKV("time_left_in_cycle", count_seconds(connman.GetMaxOutboundTimeLeftInCycle()));
obj.pushKV("uploadtarget", outboundLimit);
obj.pushKV("uploadtarget", std::move(outboundLimit));
return obj;
},
};
@@ -607,7 +607,7 @@ static UniValue GetNetworksInfo()
obj.pushKV("reachable", g_reachable_nets.Contains(network));
obj.pushKV("proxy", proxy.IsValid() ? proxy.ToString() : std::string());
obj.pushKV("proxy_randomize_credentials", proxy.m_randomize_credentials);
networks.push_back(obj);
networks.push_back(std::move(obj));
}
return networks;
}
@@ -709,10 +709,10 @@ static RPCHelpMan getnetworkinfo()
rec.pushKV("address", item.first.ToStringAddr());
rec.pushKV("port", item.second.nPort);
rec.pushKV("score", item.second.nScore);
localAddresses.push_back(rec);
localAddresses.push_back(std::move(rec));
}
}
obj.pushKV("localaddresses", localAddresses);
obj.pushKV("localaddresses", std::move(localAddresses));
obj.pushKV("warnings", GetNodeWarnings(IsDeprecatedRPCEnabled("warnings")));
return obj;
},
@@ -843,7 +843,7 @@ static RPCHelpMan listbanned()
rec.pushKV("ban_duration", (banEntry.nBanUntil - banEntry.nCreateTime));
rec.pushKV("time_remaining", (banEntry.nBanUntil - current_time));
bannedAddresses.push_back(rec);
bannedAddresses.push_back(std::move(rec));
}
return bannedAddresses;
@@ -947,7 +947,7 @@ static RPCHelpMan getnodeaddresses()
obj.pushKV("address", addr.ToStringAddr());
obj.pushKV("port", addr.GetPort());
obj.pushKV("network", GetNetworkName(addr.GetNetClass()));
ret.push_back(obj);
ret.push_back(std::move(obj));
}
return ret;
},
@@ -1087,13 +1087,13 @@ static RPCHelpMan getaddrmaninfo()
obj.pushKV("new", addrman.Size(network, true));
obj.pushKV("tried", addrman.Size(network, false));
obj.pushKV("total", addrman.Size(network));
ret.pushKV(GetNetworkName(network), obj);
ret.pushKV(GetNetworkName(network), std::move(obj));
}
UniValue obj(UniValue::VOBJ);
obj.pushKV("new", addrman.Size(std::nullopt, true));
obj.pushKV("tried", addrman.Size(std::nullopt, false));
obj.pushKV("total", addrman.Size());
ret.pushKV("all_networks", obj);
ret.pushKV("all_networks", std::move(obj));
return ret;
},
};