diff options
| author | Henny022p <info@henny022.de> | 2021-11-27 07:53:11 +0100 |
|---|---|---|
| committer | Henny022p <info@henny022.de> | 2021-11-27 07:53:11 +0100 |
| commit | 9cc2fcf9ea081472379b91abf888d50ec1de3830 (patch) | |
| tree | 4512f7fff857a8d2ecc55694c5238914c635d064 | |
| parent | 9e9dc07d23d42863f6f7ef5891898c87eb2fa015 (diff) | |
remove data copy from reader class
| -rw-r--r-- | tools/src/asset_processor/reader.cpp | 3 | ||||
| -rw-r--r-- | tools/src/asset_processor/reader.h | 28 | ||||
| -rw-r--r-- | tools/src/asset_processor/util.h | 12 | ||||
| -rw-r--r-- | tools/src/util/dummy.cpp | 1 | ||||
| -rw-r--r-- | tools/src/util/util/types.h | 15 |
5 files changed, 26 insertions, 33 deletions
diff --git a/tools/src/asset_processor/reader.cpp b/tools/src/asset_processor/reader.cpp deleted file mode 100644 index f1d28293..00000000 --- a/tools/src/asset_processor/reader.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "reader.h" -#include "util.h" -#include <string> diff --git a/tools/src/asset_processor/reader.h b/tools/src/asset_processor/reader.h index d375735b..021ea3c8 100644 --- a/tools/src/asset_processor/reader.h +++ b/tools/src/asset_processor/reader.h @@ -1,46 +1,36 @@ #ifndef READER_H #define READER_H -#include <cstdint> #include <vector> - -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef uint64_t u64; -typedef int8_t s8; -typedef int16_t s16; -typedef int32_t s32; -typedef int64_t s64; +#include <util/types.h> class Reader { public: - Reader(const std::vector<char>& baserom, int start, int size) { - auto first = baserom.begin() + start; - auto last = baserom.begin() + start + size; - data = std::vector<char>(first, last); + Reader(const std::vector<char>& baserom, int start, int size_) : data(baserom.data() + start), size(size_) { } - s8 read_s8() { + [[nodiscard]] s8 read_s8() { + // TODO range check return data[static_cast<unsigned long>(cursor++)]; } - u8 read_u8() { + [[nodiscard]] u8 read_u8() { return static_cast<u8>(read_s8()); } - u16 read_u16() { + [[nodiscard]] u16 read_u16() { return static_cast<u16>(read_u8() + (read_u8() << 8)); } - u32 read_u32() { + [[nodiscard]] u32 read_u32() { return static_cast<u32>(read_u16() + (read_u16() << 16)); } int cursor = 0; private: - std::vector<char> data; + const char* data; + const int size; }; #endif
\ No newline at end of file diff --git a/tools/src/asset_processor/util.h b/tools/src/asset_processor/util.h index 111b4e47..00781a20 100644 --- a/tools/src/asset_processor/util.h +++ b/tools/src/asset_processor/util.h @@ -4,20 +4,10 @@ #include <nlohmann/json_fwd.hpp> #include <memory> #include <stdexcept> -#include <stdint.h> -#include <stdlib.h> +#include <cstdlib> #include <string> #include <vector> -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef uint64_t u64; -typedef int8_t s8; -typedef int16_t s16; -typedef int32_t s32; -typedef int64_t s64; - void check_call(const std::vector<std::string>& cmd); std::string opt_param(const std::string& format, int defaultVal, int value); diff --git a/tools/src/util/dummy.cpp b/tools/src/util/dummy.cpp index e64e616c..c20979ec 100644 --- a/tools/src/util/dummy.cpp +++ b/tools/src/util/dummy.cpp @@ -1,3 +1,4 @@ +#include "util/types.h" #include "util/file.h" int main() { diff --git a/tools/src/util/util/types.h b/tools/src/util/util/types.h new file mode 100644 index 00000000..ef3e98f7 --- /dev/null +++ b/tools/src/util/util/types.h @@ -0,0 +1,15 @@ +#ifndef TOOLS_TYPES_H +#define TOOLS_TYPES_H + +#include <cstdint> + +using s8 = int8_t; +using u8 = uint8_t; +using s16 = int16_t; +using u16 = uint16_t; +using s32 = int32_t; +using u32 = uint32_t; +using s64 = int64_t; +using u64 = uint64_t; + +#endif // TOOLS_TYPES_H |
