diff options
| author | Lioncash <mathew1800@gmail.com> | 2020-08-05 11:47:41 -0400 |
|---|---|---|
| committer | Lioncash <mathew1800@gmail.com> | 2020-08-05 12:37:00 -0400 |
| commit | 0a5456feb9bc2a0e7f02b4b7cee34f0353e76b59 (patch) | |
| tree | e88b639971d1b41d944829db79083e92b7548415 /src/core/file_sys/vfs_vector.h | |
| parent | 142930e60929daedebded1b83066a7e7edcf0af5 (diff) | |
vfs_vector: Make creation of array vfs files less verbose
We can add a helper function to make creation of these files nicer.
While we're at it, we can eliminate an unnecessary std::array copy in
the constructor. This makes the overhead on some of these functions way
less intensive, given some arrays were quite large.
e.g. The timezone location names are 9633 bytes in size.
Diffstat (limited to 'src/core/file_sys/vfs_vector.h')
| -rw-r--r-- | src/core/file_sys/vfs_vector.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/core/file_sys/vfs_vector.h b/src/core/file_sys/vfs_vector.h index ac36cb2ee..95d3da2f2 100644 --- a/src/core/file_sys/vfs_vector.h +++ b/src/core/file_sys/vfs_vector.h @@ -4,7 +4,11 @@ #pragma once +#include <array> #include <cstring> +#include <memory> +#include <string> +#include <vector> #include "core/file_sys/vfs.h" namespace FileSys { @@ -13,7 +17,8 @@ namespace FileSys { template <std::size_t size> class ArrayVfsFile : public VfsFile { public: - ArrayVfsFile(std::array<u8, size> data, std::string name = "", VirtualDir parent = nullptr) + explicit ArrayVfsFile(const std::array<u8, size>& data, std::string name = "", + VirtualDir parent = nullptr) : data(data), name(std::move(name)), parent(std::move(parent)) {} std::string GetName() const override { @@ -61,6 +66,12 @@ private: VirtualDir parent; }; +template <std::size_t Size, typename... Args> +std::shared_ptr<ArrayVfsFile<Size>> MakeArrayFile(const std::array<u8, Size>& data, + Args&&... args) { + return std::make_shared<ArrayVfsFile<Size>>(data, std::forward<Args>(args)...); +} + // An implementation of VfsFile that is backed by a vector optionally supplied upon construction class VectorVfsFile : public VfsFile { public: |
