Skip to content
Snippets Groups Projects
Unverified Commit 69cd213f authored by bunnei's avatar bunnei Committed by GitHub
Browse files

Merge pull request #990 from lioncash/entry

 fsp_srv: Emplace entries first when building index instead of emplacing last
parents 05c33d89 7353cfc7
No related branches found
No related tags found
No related merge requests found
...@@ -4,8 +4,9 @@ ...@@ -4,8 +4,9 @@
#pragma once #pragma once
#include <array>
#include <cstddef> #include <cstddef>
#include <iterator>
#include <string_view>
#include "common/common_funcs.h" #include "common/common_funcs.h"
#include "common/common_types.h" #include "common/common_types.h"
...@@ -21,9 +22,14 @@ enum EntryType : u8 { ...@@ -21,9 +22,14 @@ enum EntryType : u8 {
// Structure of a directory entry, from // Structure of a directory entry, from
// http://switchbrew.org/index.php?title=Filesystem_services#DirectoryEntry // http://switchbrew.org/index.php?title=Filesystem_services#DirectoryEntry
const size_t FILENAME_LENGTH = 0x300;
struct Entry { struct Entry {
char filename[FILENAME_LENGTH]; Entry(std::string_view view, EntryType entry_type, u64 entry_size)
: type{entry_type}, file_size{entry_size} {
const size_t copy_size = view.copy(filename, std::size(filename) - 1);
filename[copy_size] = '\0';
}
char filename[0x300];
INSERT_PADDING_BYTES(4); INSERT_PADDING_BYTES(4);
EntryType type; EntryType type;
INSERT_PADDING_BYTES(3); INSERT_PADDING_BYTES(3);
......
...@@ -193,13 +193,10 @@ private: ...@@ -193,13 +193,10 @@ private:
template <typename T> template <typename T>
static void BuildEntryIndex(std::vector<FileSys::Entry>& entries, const std::vector<T>& new_data, static void BuildEntryIndex(std::vector<FileSys::Entry>& entries, const std::vector<T>& new_data,
FileSys::EntryType type) { FileSys::EntryType type) {
entries.reserve(entries.size() + new_data.size());
for (const auto& new_entry : new_data) { for (const auto& new_entry : new_data) {
FileSys::Entry entry; entries.emplace_back(new_entry->GetName(), type, new_entry->GetSize());
entry.filename[0] = '\0';
std::strncat(entry.filename, new_entry->GetName().c_str(), FileSys::FILENAME_LENGTH - 1);
entry.type = type;
entry.file_size = new_entry->GetSize();
entries.emplace_back(std::move(entry));
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment