mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-11-01 12:57:52 +00:00
7f0f37fca7
Previously the constructor for all of these would run at program startup, consuming time before the application can enter main(). This is also particularly dangerous, given the logging system wouldn't have been initialized properly yet, yet the program would use the logs to signify an error. To rectify this, we can replace the literals with constexpr functions that perform the conversion at compile-time, completely eliminating the runtime cost of initializing these arrays.
21 lines
700 B
C++
21 lines
700 B
C++
// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
|
|
// Licensed under GPLv2 or any later version
|
|
// Refer to the license.txt file included.
|
|
|
|
#include "common/hex_util.h"
|
|
|
|
namespace Common {
|
|
|
|
std::vector<u8> HexStringToVector(std::string_view str, bool little_endian) {
|
|
std::vector<u8> out(str.size() / 2);
|
|
if (little_endian) {
|
|
for (std::size_t i = str.size() - 2; i <= str.size(); i -= 2)
|
|
out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]);
|
|
} else {
|
|
for (std::size_t i = 0; i < str.size(); i += 2)
|
|
out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
} // namespace Common
|