summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2018-08-08 17:39:00 -0400
committerGravatar Lioncash2018-08-08 18:51:41 -0400
commit4afb05d0cc35f36ea145768f052755554d9494fc (patch)
tree92e2c1c71a023514670903f7219740333808fc41 /src
parentMerge pull request #966 from lioncash/modernize (diff)
downloadyuzu-4afb05d0cc35f36ea145768f052755554d9494fc.tar.gz
yuzu-4afb05d0cc35f36ea145768f052755554d9494fc.tar.xz
yuzu-4afb05d0cc35f36ea145768f052755554d9494fc.zip
fsp_srv: Emplace entries first when building index instead of emplacing last
The current way were doing it would require copying a 768 character buffer (part of the Entry struct) to the new element in the vector. Given it's a plain array, std::move won't eliminate that. Instead, we can emplace an instance directly into the destination buffer and then fill it out, avoiding the need to perform any unnecessary copies. Given this is done in a loop, we can request the destination to allocate all of the necessary memory ahead of time, avoiding the need to potentially keep reallocating over and over on every few insertions into the vector.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp
index e7ffb6bd1..4110e67b4 100644
--- a/src/core/hle/service/filesystem/fsp_srv.cpp
+++ b/src/core/hle/service/filesystem/fsp_srv.cpp
@@ -193,13 +193,14 @@ private:
193template <typename T> 193template <typename T>
194static void BuildEntryIndex(std::vector<FileSys::Entry>& entries, const std::vector<T>& new_data, 194static void BuildEntryIndex(std::vector<FileSys::Entry>& entries, const std::vector<T>& new_data,
195 FileSys::EntryType type) { 195 FileSys::EntryType type) {
196 entries.reserve(entries.size() + new_data.size());
197
196 for (const auto& new_entry : new_data) { 198 for (const auto& new_entry : new_data) {
197 FileSys::Entry entry; 199 auto& entry = entries.emplace_back();
198 entry.filename[0] = '\0'; 200 entry.filename[0] = '\0';
199 std::strncat(entry.filename, new_entry->GetName().c_str(), FileSys::FILENAME_LENGTH - 1); 201 std::strncat(entry.filename, new_entry->GetName().c_str(), FileSys::FILENAME_LENGTH - 1);
200 entry.type = type; 202 entry.type = type;
201 entry.file_size = new_entry->GetSize(); 203 entry.file_size = new_entry->GetSize();
202 entries.emplace_back(std::move(entry));
203 } 204 }
204} 205}
205 206