From b89f644cfef7592a501f1c0b9aae0c4ae757d854 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Wed, 6 May 2015 02:29:11 -0300 Subject: [PATCH] FileSys: De-inline Path members --- src/core/CMakeLists.txt | 1 + src/core/file_sys/archive_backend.cpp | 127 ++++++++++++++++++++++++ src/core/file_sys/archive_backend.h | 134 ++------------------------ src/core/hle/service/cfg/cfg.cpp | 2 + 4 files changed, 139 insertions(+), 125 deletions(-) create mode 100644 src/core/file_sys/archive_backend.cpp diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 42733b95e..fa6b4215a 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -12,6 +12,7 @@ set(SRCS arm/skyeye_common/vfp/vfpdouble.cpp arm/skyeye_common/vfp/vfpinstr.cpp arm/skyeye_common/vfp/vfpsingle.cpp + file_sys/archive_backend.cpp file_sys/archive_extsavedata.cpp file_sys/archive_romfs.cpp file_sys/archive_savedata.cpp diff --git a/src/core/file_sys/archive_backend.cpp b/src/core/file_sys/archive_backend.cpp new file mode 100644 index 000000000..0439868ab --- /dev/null +++ b/src/core/file_sys/archive_backend.cpp @@ -0,0 +1,127 @@ +// Copyright 2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include + +#include "common/logging/log.h" +#include "common/string_util.h" + +#include "core/file_sys/archive_backend.h" +#include "core/mem_map.h" + + +namespace FileSys { + +Path::Path(LowPathType type, u32 size, u32 pointer) : type(type) { + switch (type) { + case Binary: + { + u8* data = Memory::GetPointer(pointer); + binary = std::vector(data, data + size); + break; + } + + case Char: + { + const char* data = reinterpret_cast(Memory::GetPointer(pointer)); + string = std::string(data, size - 1); // Data is always null-terminated. + break; + } + + case Wchar: + { + const char16_t* data = reinterpret_cast(Memory::GetPointer(pointer)); + u16str = std::u16string(data, size/2 - 1); // Data is always null-terminated. + break; + } + + default: + break; + } +} + +const std::string Path::DebugStr() const { + switch (GetType()) { + case Invalid: + default: + return "[Invalid]"; + case Empty: + return "[Empty]"; + case Binary: + { + std::stringstream res; + res << "[Binary: "; + for (unsigned byte : binary) + res << std::hex << std::setw(2) << std::setfill('0') << byte; + res << ']'; + return res.str(); + } + case Char: + return "[Char: " + AsString() + ']'; + case Wchar: + return "[Wchar: " + AsString() + ']'; + } +} + +const std::string Path::AsString() const { + switch (GetType()) { + case Char: + return string; + case Wchar: + return Common::UTF16ToUTF8(u16str); + case Empty: + return{}; + case Invalid: + case Binary: + default: + // TODO(yuriks): Add assert + LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!"); + return{}; + } +} + +const std::u16string Path::AsU16Str() const { + switch (GetType()) { + case Char: + return Common::UTF8ToUTF16(string); + case Wchar: + return u16str; + case Empty: + return{}; + case Invalid: + case Binary: + // TODO(yuriks): Add assert + LOG_ERROR(Service_FS, "LowPathType cannot be converted to u16string!"); + return{}; + } +} + +const std::vector Path::AsBinary() const { + switch (GetType()) { + case Binary: + return binary; + case Char: + return std::vector(string.begin(), string.end()); + case Wchar: + { + // use two u8 for each character of u16str + std::vector to_return(u16str.size() * 2); + for (size_t i = 0; i < u16str.size(); ++i) { + u16 tmp_char = u16str.at(i); + to_return[i*2] = (tmp_char & 0xFF00) >> 8; + to_return[i*2 + 1] = (tmp_char & 0x00FF); + } + return to_return; + } + case Empty: + return{}; + case Invalid: + default: + // TODO(yuriks): Add assert + LOG_ERROR(Service_FS, "LowPathType cannot be converted to binary!"); + return{}; + } +} + +} diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h index 1956d76cb..c6a1be79d 100644 --- a/src/core/file_sys/archive_backend.h +++ b/src/core/file_sys/archive_backend.h @@ -5,18 +5,14 @@ #pragma once #include -#include #include #include #include #include "common/bit_field.h" #include "common/common_types.h" -#include "common/logging/log.h" -#include "common/string_util.h" #include "core/hle/result.h" -#include "core/mem_map.h" namespace FileSys { @@ -42,134 +38,22 @@ union Mode { class Path { public: + Path() : type(Invalid) {} + Path(const char* path) : type(Char), string(path) {} + Path(std::vector binary_data) : type(Binary), binary(std::move(binary_data)) {} + Path(LowPathType type, u32 size, u32 pointer); - Path() : type(Invalid) { - } - - Path(const char* path) : type(Char), string(path) { - } - - Path(std::vector binary_data) : type(Binary), binary(std::move(binary_data)) { - } - - Path(LowPathType type, u32 size, u32 pointer) : type(type) { - switch (type) { - case Binary: - { - u8* data = Memory::GetPointer(pointer); - binary = std::vector(data, data + size); - break; - } - - case Char: - { - const char* data = reinterpret_cast(Memory::GetPointer(pointer)); - string = std::string(data, size - 1); // Data is always null-terminated. - break; - } - - case Wchar: - { - const char16_t* data = reinterpret_cast(Memory::GetPointer(pointer)); - u16str = std::u16string(data, size/2 - 1); // Data is always null-terminated. - break; - } - - default: - break; - } - } - - LowPathType GetType() const { - return type; - } + LowPathType GetType() const { return type; } /** * Gets the string representation of the path for debugging * @return String representation of the path for debugging */ - const std::string DebugStr() const { - switch (GetType()) { - case Invalid: - default: - return "[Invalid]"; - case Empty: - return "[Empty]"; - case Binary: - { - std::stringstream res; - res << "[Binary: "; - for (unsigned byte : binary) - res << std::hex << std::setw(2) << std::setfill('0') << byte; - res << ']'; - return res.str(); - } - case Char: - return "[Char: " + AsString() + ']'; - case Wchar: - return "[Wchar: " + AsString() + ']'; - } - } + const std::string DebugStr() const; - const std::string AsString() const { - switch (GetType()) { - case Char: - return string; - case Wchar: - return Common::UTF16ToUTF8(u16str); - case Empty: - return {}; - case Invalid: - case Binary: - default: - // TODO(yuriks): Add assert - LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!"); - return {}; - } - } - - const std::u16string AsU16Str() const { - switch (GetType()) { - case Char: - return Common::UTF8ToUTF16(string); - case Wchar: - return u16str; - case Empty: - return {}; - case Invalid: - case Binary: - // TODO(yuriks): Add assert - LOG_ERROR(Service_FS, "LowPathType cannot be converted to u16string!"); - return {}; - } - } - - const std::vector AsBinary() const { - switch (GetType()) { - case Binary: - return binary; - case Char: - return std::vector(string.begin(), string.end()); - case Wchar: - { - // use two u8 for each character of u16str - std::vector to_return(u16str.size() * 2); - for (size_t i = 0; i < u16str.size(); ++i) { - u16 tmp_char = u16str.at(i); - to_return[i*2] = (tmp_char & 0xFF00) >> 8; - to_return[i*2 + 1] = (tmp_char & 0x00FF); - } - return to_return; - } - case Empty: - return {}; - case Invalid: - default: - // TODO(yuriks): Add assert - LOG_ERROR(Service_FS, "LowPathType cannot be converted to binary!"); - return {}; - } - } + const std::string AsString() const; + const std::u16string AsU16Str() const; + const std::vector AsBinary() const; private: LowPathType type; diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index 94bac5498..207f660e6 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp @@ -4,6 +4,8 @@ #include +#include "common/string_util.h" + #include "core/file_sys/file_backend.h" #include "core/hle/service/cfg/cfg.h" #include "core/hle/service/cfg/cfg_i.h"