summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2018-07-19 10:15:00 -0400
committerGravatar Lioncash2018-07-19 10:46:54 -0400
commit3e9b79e088223459891ed07a747c411a6a8921d3 (patch)
treef65cb57670b5d421c394a598202df35d4f1eb267 /src
parentfsp_srv: Make IStorage constructor explicit (diff)
downloadyuzu-3e9b79e088223459891ed07a747c411a6a8921d3.tar.gz
yuzu-3e9b79e088223459891ed07a747c411a6a8921d3.tar.xz
yuzu-3e9b79e088223459891ed07a747c411a6a8921d3.zip
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).
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp
index 4cb2d6909..673eaabf0 100644
--- a/src/core/hle/service/filesystem/fsp_srv.cpp
+++ b/src/core/hle/service/filesystem/fsp_srv.cpp
@@ -4,6 +4,7 @@
4 4
5#include <cinttypes> 5#include <cinttypes>
6#include <cstring> 6#include <cstring>
7#include <iterator>
7#include <string> 8#include <string>
8#include <utility> 9#include <utility>
9#include <vector> 10#include <vector>
@@ -229,23 +230,20 @@ private:
229 LOG_DEBUG(Service_FS, "called, unk=0x{:X}", unk); 230 LOG_DEBUG(Service_FS, "called, unk=0x{:X}", unk);
230 231
231 // Calculate how many entries we can fit in the output buffer 232 // Calculate how many entries we can fit in the output buffer
232 u64 count_entries = ctx.GetWriteBufferSize() / sizeof(FileSys::Entry); 233 const u64 count_entries = ctx.GetWriteBufferSize() / sizeof(FileSys::Entry);
233 234
234 // Cap at total number of entries. 235 // Cap at total number of entries.
235 u64 actual_entries = std::min(count_entries, entries.size() - next_entry_index); 236 const u64 actual_entries = std::min(count_entries, entries.size() - next_entry_index);
236 237
237 // Read the data from the Directory backend 238 // Determine data start and end
238 std::vector<FileSys::Entry> entry_data(entries.begin() + next_entry_index, 239 const auto* begin = reinterpret_cast<u8*>(entries.data() + next_entry_index);
239 entries.begin() + next_entry_index + actual_entries); 240 const auto* end = reinterpret_cast<u8*>(entries.data() + next_entry_index + actual_entries);
241 const auto range_size = static_cast<std::size_t>(std::distance(begin, end));
240 242
241 next_entry_index += actual_entries; 243 next_entry_index += actual_entries;
242 244
243 // Convert the data into a byte array
244 std::vector<u8> output(entry_data.size() * sizeof(FileSys::Entry));
245 std::memcpy(output.data(), entry_data.data(), output.size());
246
247 // Write the data to memory 245 // Write the data to memory
248 ctx.WriteBuffer(output); 246 ctx.WriteBuffer(begin, range_size);
249 247
250 IPC::ResponseBuilder rb{ctx, 4}; 248 IPC::ResponseBuilder rb{ctx, 4};
251 rb.Push(RESULT_SUCCESS); 249 rb.Push(RESULT_SUCCESS);