2
1
Fork 0
mirror of https://github.com/yuzu-emu/yuzu.git synced 2024-07-04 23:31:19 +01:00

fsp_srv: Remove unnecessary std::vector construction in IDirectory's Read() function

We were using a second std::vector as a buffer to convert another
std::vector's data into a byte sequence, however we can just use
pointers to the original data and use them directly with WriteBuffer,
which avoids copying the data at all into a separate std::vector.

We simply cast the pointers to u8* (which is allowed by the standard,
given std::uint8_t is an alias for unsigned char on platforms that we
support).
This commit is contained in:
Lioncash 2018-07-19 10:15:00 -04:00
parent f317080f40
commit 3e9b79e088

View file

@ -4,6 +4,7 @@
#include <cinttypes> #include <cinttypes>
#include <cstring> #include <cstring>
#include <iterator>
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -229,23 +230,20 @@ private:
LOG_DEBUG(Service_FS, "called, unk=0x{:X}", unk); LOG_DEBUG(Service_FS, "called, unk=0x{:X}", unk);
// Calculate how many entries we can fit in the output buffer // Calculate how many entries we can fit in the output buffer
u64 count_entries = ctx.GetWriteBufferSize() / sizeof(FileSys::Entry); const u64 count_entries = ctx.GetWriteBufferSize() / sizeof(FileSys::Entry);
// Cap at total number of entries. // Cap at total number of entries.
u64 actual_entries = std::min(count_entries, entries.size() - next_entry_index); const u64 actual_entries = std::min(count_entries, entries.size() - next_entry_index);
// Read the data from the Directory backend // Determine data start and end
std::vector<FileSys::Entry> entry_data(entries.begin() + next_entry_index, const auto* begin = reinterpret_cast<u8*>(entries.data() + next_entry_index);
entries.begin() + next_entry_index + actual_entries); const auto* end = reinterpret_cast<u8*>(entries.data() + next_entry_index + actual_entries);
const auto range_size = static_cast<std::size_t>(std::distance(begin, end));
next_entry_index += actual_entries; next_entry_index += actual_entries;
// Convert the data into a byte array
std::vector<u8> output(entry_data.size() * sizeof(FileSys::Entry));
std::memcpy(output.data(), entry_data.data(), output.size());
// Write the data to memory // Write the data to memory
ctx.WriteBuffer(output); ctx.WriteBuffer(begin, range_size);
IPC::ResponseBuilder rb{ctx, 4}; IPC::ResponseBuilder rb{ctx, 4};
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);