[Base] Add user-literals for several memory sizes
Rather than using `n * 1024 * 1024`, this adds a convenient `_MiB`/`_KiB` user-literal to the new `literals.h` header to concisely describe units of memory in a much more readable way. Any other useful literals can be added to this header. These literals exist in the `xe::literals` namespace so they are opt-in, similar to `std::chrono` literals, and require a `using namespace xe::literals` statement to utilize it within the current scope. I've done a pass through the codebase to replace trivial instances of `1024 * 1024 * ...` expressions being used but avoided anything that added additional casting complexity from `size_t` to `uint32_t` and such to keep this commit concise.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "xenia/vfs/devices/disc_image_device.h"
|
||||
|
||||
#include "xenia/base/literals.h"
|
||||
#include "xenia/base/logging.h"
|
||||
#include "xenia/base/math.h"
|
||||
#include "xenia/vfs/devices/disc_image_entry.h"
|
||||
@@ -16,7 +17,9 @@
|
||||
namespace xe {
|
||||
namespace vfs {
|
||||
|
||||
const size_t kXESectorSize = 2048;
|
||||
using namespace xe::literals;
|
||||
|
||||
const size_t kXESectorSize = 2_KiB;
|
||||
|
||||
DiscImageDevice::DiscImageDevice(const std::string_view mount_path,
|
||||
const std::filesystem::path& host_path)
|
||||
@@ -89,7 +92,7 @@ DiscImageDevice::Error DiscImageDevice::Verify(ParseState* state) {
|
||||
state->root_size = xe::load<uint32_t>(fs_ptr + 24);
|
||||
state->root_offset =
|
||||
state->game_offset + (state->root_sector * kXESectorSize);
|
||||
if (state->root_size < 13 || state->root_size > 32 * 1024 * 1024) {
|
||||
if (state->root_size < 13 || state->root_size > 32_MiB) {
|
||||
return Error::kErrorDamagedFile;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "xenia/base/console_app_main.h"
|
||||
#include "xenia/base/cvar.h"
|
||||
#include "xenia/base/literals.h"
|
||||
#include "xenia/base/logging.h"
|
||||
#include "xenia/base/math.h"
|
||||
|
||||
@@ -22,6 +23,8 @@
|
||||
namespace xe {
|
||||
namespace vfs {
|
||||
|
||||
using namespace xe::literals;
|
||||
|
||||
DEFINE_transient_path(source, "", "Specifies the file to dump from.",
|
||||
"General");
|
||||
|
||||
@@ -91,7 +94,7 @@ int vfs_dump_main(const std::vector<std::string>& args) {
|
||||
}
|
||||
|
||||
// Allocate a buffer rounded up to the nearest 512MB.
|
||||
buffer_size = xe::round_up(entry->size(), 512 * 1024 * 1024);
|
||||
buffer_size = xe::round_up(entry->size(), 512_MiB);
|
||||
buffer = new uint8_t[buffer_size];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user