[Misc] Replaced const with constexpr where possible
This commit is contained in:
committed by
Radosław Gliński
parent
d20620eb5e
commit
5f918ef28d
@@ -168,7 +168,7 @@ static void ExceptionHandlerCallback(int signal_number, siginfo_t* signal_info,
|
||||
mcontext.gregs[REG_EFL] = greg_t(thread_context.eflags);
|
||||
uint32_t modified_register_index;
|
||||
// The order must match the order in X64Register.
|
||||
static const size_t kIntRegisterMap[] = {
|
||||
static constexpr size_t kIntRegisterMap[] = {
|
||||
REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP,
|
||||
REG_RSI, REG_RDI, REG_R8, REG_R9, REG_R10, REG_R11,
|
||||
REG_R12, REG_R13, REG_R14, REG_R15,
|
||||
|
||||
@@ -65,14 +65,14 @@ bool TruncateStdioFile(FILE* file, uint64_t length);
|
||||
|
||||
struct FileAccess {
|
||||
// Implies kFileReadData.
|
||||
static const uint32_t kGenericRead = 0x80000000;
|
||||
static constexpr uint32_t kGenericRead = 0x80000000;
|
||||
// Implies kFileWriteData.
|
||||
static const uint32_t kGenericWrite = 0x40000000;
|
||||
static const uint32_t kGenericExecute = 0x20000000;
|
||||
static const uint32_t kGenericAll = 0x10000000;
|
||||
static const uint32_t kFileReadData = 0x00000001;
|
||||
static const uint32_t kFileWriteData = 0x00000002;
|
||||
static const uint32_t kFileAppendData = 0x00000004;
|
||||
static constexpr uint32_t kGenericWrite = 0x40000000;
|
||||
static constexpr uint32_t kGenericExecute = 0x20000000;
|
||||
static constexpr uint32_t kGenericAll = 0x10000000;
|
||||
static constexpr uint32_t kFileReadData = 0x00000001;
|
||||
static constexpr uint32_t kFileWriteData = 0x00000002;
|
||||
static constexpr uint32_t kFileAppendData = 0x00000004;
|
||||
};
|
||||
|
||||
class FileHandle {
|
||||
|
||||
@@ -214,7 +214,7 @@ bool IsAndroidContentUri(const std::string_view source) {
|
||||
// still including // in the comparison to distinguish from a file with a name
|
||||
// starting from content: (as this is the main purpose of this code -
|
||||
// separating URIs from file paths) more clearly.
|
||||
static const char kContentSchema[] = "content://";
|
||||
static constexpr char kContentSchema[] = "content://";
|
||||
constexpr size_t kContentSchemaLength = xe::countof(kContentSchema) - 1;
|
||||
return source.size() >= kContentSchemaLength &&
|
||||
!xe_strncasecmp(source.data(), kContentSchema, kContentSchemaLength);
|
||||
|
||||
@@ -14,23 +14,23 @@
|
||||
|
||||
namespace xe::literals {
|
||||
|
||||
constexpr size_t operator""_KiB(unsigned long long int x) {
|
||||
constexpr size_t operator""_KiB(const unsigned long long int x) {
|
||||
return 1024ULL * x;
|
||||
}
|
||||
|
||||
constexpr size_t operator""_MiB(unsigned long long int x) {
|
||||
constexpr size_t operator""_MiB(const unsigned long long int x) {
|
||||
return 1024_KiB * x;
|
||||
}
|
||||
|
||||
constexpr size_t operator""_GiB(unsigned long long int x) {
|
||||
constexpr size_t operator""_GiB(const unsigned long long int x) {
|
||||
return 1024_MiB * x;
|
||||
}
|
||||
|
||||
constexpr size_t operator""_TiB(unsigned long long int x) {
|
||||
constexpr size_t operator""_TiB(const unsigned long long int x) {
|
||||
return 1024_GiB * x;
|
||||
}
|
||||
|
||||
constexpr size_t operator""_PiB(unsigned long long int x) {
|
||||
constexpr size_t operator""_PiB(const unsigned long long int x) {
|
||||
return 1024_TiB * x;
|
||||
}
|
||||
|
||||
|
||||
@@ -244,10 +244,10 @@ class Logger {
|
||||
}
|
||||
|
||||
private:
|
||||
static const size_t kBufferSize = 8_MiB;
|
||||
static constexpr size_t kBufferSize = 8_MiB;
|
||||
uint8_t buffer_[kBufferSize];
|
||||
|
||||
static const size_t kBlockSize = 256;
|
||||
static constexpr size_t kBlockSize = 256;
|
||||
static const size_t kBlockCount = kBufferSize / kBlockSize;
|
||||
static const size_t kBlockIndexMask = kBlockCount - 1;
|
||||
|
||||
|
||||
@@ -181,12 +181,12 @@
|
||||
namespace xe {
|
||||
|
||||
#if XE_PLATFORM_WIN32
|
||||
const char kPathSeparator = '\\';
|
||||
constexpr char kPathSeparator = '\\';
|
||||
#else
|
||||
const char kPathSeparator = '/';
|
||||
constexpr char kPathSeparator = '/';
|
||||
#endif // XE_PLATFORM_WIN32
|
||||
|
||||
const char kGuestPathSeparator = '\\';
|
||||
constexpr char kGuestPathSeparator = '\\';
|
||||
|
||||
} // namespace xe
|
||||
#if XE_ARCH_AMD64 == 1
|
||||
|
||||
@@ -516,7 +516,7 @@ TEST_CASE("create_and_close_file_mapping", "Virtual Memory Mapping") {
|
||||
|
||||
TEST_CASE("map_view", "[virtual_memory_mapping]") {
|
||||
auto path = fmt::format("xenia_test_{}", Clock::QueryHostTickCount());
|
||||
const size_t length = 0x100;
|
||||
constexpr size_t length = 0x100;
|
||||
auto memory = xe::memory::CreateFileMappingHandle(
|
||||
path, length, xe::memory::PageAccess::kReadWrite, true);
|
||||
REQUIRE(memory != xe::memory::kFileMappingHandleInvalid);
|
||||
@@ -532,7 +532,7 @@ TEST_CASE("map_view", "[virtual_memory_mapping]") {
|
||||
}
|
||||
|
||||
TEST_CASE("read_write_view", "[virtual_memory_mapping]") {
|
||||
const size_t length = 0x100;
|
||||
constexpr size_t length = 0x100;
|
||||
auto path = fmt::format("xenia_test_{}", Clock::QueryHostTickCount());
|
||||
auto memory = xe::memory::CreateFileMappingHandle(
|
||||
path, length, xe::memory::PageAccess::kReadWrite, true);
|
||||
|
||||
@@ -404,19 +404,19 @@ class Timer : public WaitHandle {
|
||||
|
||||
#if XE_PLATFORM_WIN32
|
||||
struct ThreadPriority {
|
||||
static const int32_t kLowest = -2;
|
||||
static const int32_t kBelowNormal = -1;
|
||||
static const int32_t kNormal = 0;
|
||||
static const int32_t kAboveNormal = 1;
|
||||
static const int32_t kHighest = 2;
|
||||
static constexpr int32_t kLowest = -2;
|
||||
static constexpr int32_t kBelowNormal = -1;
|
||||
static constexpr int32_t kNormal = 0;
|
||||
static constexpr int32_t kAboveNormal = 1;
|
||||
static constexpr int32_t kHighest = 2;
|
||||
};
|
||||
#else
|
||||
struct ThreadPriority {
|
||||
static const int32_t kLowest = 1;
|
||||
static const int32_t kBelowNormal = 8;
|
||||
static const int32_t kNormal = 16;
|
||||
static const int32_t kAboveNormal = 24;
|
||||
static const int32_t kHighest = 32;
|
||||
static constexpr int32_t kLowest = 1;
|
||||
static constexpr int32_t kBelowNormal = 8;
|
||||
static constexpr int32_t kNormal = 16;
|
||||
static constexpr int32_t kAboveNormal = 24;
|
||||
static constexpr int32_t kHighest = 32;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@@ -82,10 +82,10 @@ std::string upper_ascii(const std::string_view view) {
|
||||
|
||||
template <bool LOWER>
|
||||
inline size_t hash_fnv1a(const std::string_view view) {
|
||||
const size_t offset_basis = 0xCBF29CE484222325ull;
|
||||
constexpr size_t offset_basis = 0xCBF29CE484222325ull;
|
||||
// chrispy: constant capture errors on clang
|
||||
auto work = [](size_t hash, uint8_t byte_of_data) {
|
||||
const size_t prime = 0x00000100000001B3ull;
|
||||
constexpr size_t prime = 0x00000100000001B3ull;
|
||||
hash ^= byte_of_data;
|
||||
hash *= prime;
|
||||
return hash;
|
||||
|
||||
Reference in New Issue
Block a user