ipc_helpers: Make PushStaticBuffer take std::vector by value

Allows interfaces to move the vector into the calls, avoiding any
reallocations.

Many existing call sites already std::move into the parameter, expecting
a move to occur. Only a few remain where this wasn't already
being done, which we can convert over.
This commit is contained in:
Lioncash 2020-04-18 19:01:16 -04:00
parent 397bd1bb73
commit a6e37b48e9
8 changed files with 52 additions and 51 deletions

View file

@ -1124,12 +1124,12 @@ void NWM_UDS::PullPacket(Kernel::HLERequestContext& ctx) {
}
if (channel->second.received_packets.empty()) {
std::vector<u8> output_buffer(buff_size, 0);
std::vector<u8> output_buffer(buff_size);
IPC::RequestBuilder rb = rp.MakeBuilder(3, 2);
rb.Push(RESULT_SUCCESS);
rb.Push<u32>(0);
rb.Push<u16>(0);
rb.PushStaticBuffer(output_buffer, 0);
rb.PushStaticBuffer(std::move(output_buffer), 0);
return;
}
@ -1147,7 +1147,7 @@ void NWM_UDS::PullPacket(Kernel::HLERequestContext& ctx) {
IPC::RequestBuilder rb = rp.MakeBuilder(3, 2);
std::vector<u8> output_buffer(buff_size, 0);
std::vector<u8> output_buffer(buff_size);
// Write the actual data.
std::memcpy(output_buffer.data(),
next_packet.data() + sizeof(LLCHeader) + sizeof(SecureDataHeader), data_size);
@ -1155,7 +1155,7 @@ void NWM_UDS::PullPacket(Kernel::HLERequestContext& ctx) {
rb.Push(RESULT_SUCCESS);
rb.Push<u32>(data_size);
rb.Push<u16>(secure_data.src_node_id);
rb.PushStaticBuffer(output_buffer, 0);
rb.PushStaticBuffer(std::move(output_buffer), 0);
channel->second.received_packets.pop_front();
}
@ -1336,9 +1336,9 @@ void NWM_UDS::DecryptBeaconData(Kernel::HLERequestContext& ctx, u16 command_id)
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
rb.Push(RESULT_SUCCESS);
std::vector<u8> output_buffer(sizeof(NodeInfo) * UDSMaxNodes, 0);
std::vector<u8> output_buffer(sizeof(NodeInfo) * UDSMaxNodes);
std::memcpy(output_buffer.data(), nodes.data(), sizeof(NodeInfo) * nodes.size());
rb.PushStaticBuffer(output_buffer, 0);
rb.PushStaticBuffer(std::move(output_buffer), 0);
}
template <u16 command_id>