diff options
34 files changed, 343 insertions, 358 deletions
diff --git a/src/common/algorithm.h b/src/common/algorithm.h index e21b1373c..4804a3421 100644 --- a/src/common/algorithm.h +++ b/src/common/algorithm.h | |||
| @@ -15,7 +15,8 @@ | |||
| 15 | namespace Common { | 15 | namespace Common { |
| 16 | 16 | ||
| 17 | template <class ForwardIt, class T, class Compare = std::less<>> | 17 | template <class ForwardIt, class T, class Compare = std::less<>> |
| 18 | ForwardIt BinaryFind(ForwardIt first, ForwardIt last, const T& value, Compare comp = {}) { | 18 | [[nodiscard]] ForwardIt BinaryFind(ForwardIt first, ForwardIt last, const T& value, |
| 19 | Compare comp = {}) { | ||
| 19 | // Note: BOTH type T and the type after ForwardIt is dereferenced | 20 | // Note: BOTH type T and the type after ForwardIt is dereferenced |
| 20 | // must be implicitly convertible to BOTH Type1 and Type2, used in Compare. | 21 | // must be implicitly convertible to BOTH Type1 and Type2, used in Compare. |
| 21 | // This is stricter than lower_bound requirement (see above) | 22 | // This is stricter than lower_bound requirement (see above) |
diff --git a/src/common/alignment.h b/src/common/alignment.h index ef4d6f896..5040043de 100644 --- a/src/common/alignment.h +++ b/src/common/alignment.h | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | namespace Common { | 9 | namespace Common { |
| 10 | 10 | ||
| 11 | template <typename T> | 11 | template <typename T> |
| 12 | constexpr T AlignUp(T value, std::size_t size) { | 12 | [[nodiscard]] constexpr T AlignUp(T value, std::size_t size) { |
| 13 | static_assert(std::is_unsigned_v<T>, "T must be an unsigned value."); | 13 | static_assert(std::is_unsigned_v<T>, "T must be an unsigned value."); |
| 14 | auto mod{static_cast<T>(value % size)}; | 14 | auto mod{static_cast<T>(value % size)}; |
| 15 | value -= mod; | 15 | value -= mod; |
| @@ -17,31 +17,31 @@ constexpr T AlignUp(T value, std::size_t size) { | |||
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | template <typename T> | 19 | template <typename T> |
| 20 | constexpr T AlignDown(T value, std::size_t size) { | 20 | [[nodiscard]] constexpr T AlignDown(T value, std::size_t size) { |
| 21 | static_assert(std::is_unsigned_v<T>, "T must be an unsigned value."); | 21 | static_assert(std::is_unsigned_v<T>, "T must be an unsigned value."); |
| 22 | return static_cast<T>(value - value % size); | 22 | return static_cast<T>(value - value % size); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | template <typename T> | 25 | template <typename T> |
| 26 | constexpr T AlignBits(T value, std::size_t align) { | 26 | [[nodiscard]] constexpr T AlignBits(T value, std::size_t align) { |
| 27 | static_assert(std::is_unsigned_v<T>, "T must be an unsigned value."); | 27 | static_assert(std::is_unsigned_v<T>, "T must be an unsigned value."); |
| 28 | return static_cast<T>((value + ((1ULL << align) - 1)) >> align << align); | 28 | return static_cast<T>((value + ((1ULL << align) - 1)) >> align << align); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | template <typename T> | 31 | template <typename T> |
| 32 | constexpr bool Is4KBAligned(T value) { | 32 | [[nodiscard]] constexpr bool Is4KBAligned(T value) { |
| 33 | static_assert(std::is_unsigned_v<T>, "T must be an unsigned value."); | 33 | static_assert(std::is_unsigned_v<T>, "T must be an unsigned value."); |
| 34 | return (value & 0xFFF) == 0; | 34 | return (value & 0xFFF) == 0; |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | template <typename T> | 37 | template <typename T> |
| 38 | constexpr bool IsWordAligned(T value) { | 38 | [[nodiscard]] constexpr bool IsWordAligned(T value) { |
| 39 | static_assert(std::is_unsigned_v<T>, "T must be an unsigned value."); | 39 | static_assert(std::is_unsigned_v<T>, "T must be an unsigned value."); |
| 40 | return (value & 0b11) == 0; | 40 | return (value & 0b11) == 0; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | template <typename T> | 43 | template <typename T> |
| 44 | constexpr bool IsAligned(T value, std::size_t alignment) { | 44 | [[nodiscard]] constexpr bool IsAligned(T value, std::size_t alignment) { |
| 45 | using U = typename std::make_unsigned<T>::type; | 45 | using U = typename std::make_unsigned<T>::type; |
| 46 | const U mask = static_cast<U>(alignment - 1); | 46 | const U mask = static_cast<U>(alignment - 1); |
| 47 | return (value & mask) == 0; | 47 | return (value & mask) == 0; |
| @@ -64,7 +64,7 @@ public: | |||
| 64 | template <typename T2> | 64 | template <typename T2> |
| 65 | constexpr AlignmentAllocator(const AlignmentAllocator<T2, Align>&) noexcept {} | 65 | constexpr AlignmentAllocator(const AlignmentAllocator<T2, Align>&) noexcept {} |
| 66 | 66 | ||
| 67 | T* allocate(size_type n) { | 67 | [[nodiscard]] T* allocate(size_type n) { |
| 68 | return static_cast<T*>(::operator new (n * sizeof(T), std::align_val_t{Align})); | 68 | return static_cast<T*>(::operator new (n * sizeof(T), std::align_val_t{Align})); |
| 69 | } | 69 | } |
| 70 | 70 | ||
diff --git a/src/common/atomic_ops.h b/src/common/atomic_ops.h index 8d6b73c00..b46888589 100644 --- a/src/common/atomic_ops.h +++ b/src/common/atomic_ops.h | |||
| @@ -8,10 +8,10 @@ | |||
| 8 | 8 | ||
| 9 | namespace Common { | 9 | namespace Common { |
| 10 | 10 | ||
| 11 | bool AtomicCompareAndSwap(volatile u8* pointer, u8 value, u8 expected); | 11 | [[nodiscard]] bool AtomicCompareAndSwap(volatile u8* pointer, u8 value, u8 expected); |
| 12 | bool AtomicCompareAndSwap(volatile u16* pointer, u16 value, u16 expected); | 12 | [[nodiscard]] bool AtomicCompareAndSwap(volatile u16* pointer, u16 value, u16 expected); |
| 13 | bool AtomicCompareAndSwap(volatile u32* pointer, u32 value, u32 expected); | 13 | [[nodiscard]] bool AtomicCompareAndSwap(volatile u32* pointer, u32 value, u32 expected); |
| 14 | bool AtomicCompareAndSwap(volatile u64* pointer, u64 value, u64 expected); | 14 | [[nodiscard]] bool AtomicCompareAndSwap(volatile u64* pointer, u64 value, u64 expected); |
| 15 | bool AtomicCompareAndSwap(volatile u64* pointer, u128 value, u128 expected); | 15 | [[nodiscard]] bool AtomicCompareAndSwap(volatile u64* pointer, u128 value, u128 expected); |
| 16 | 16 | ||
| 17 | } // namespace Common | 17 | } // namespace Common |
diff --git a/src/common/bit_field.h b/src/common/bit_field.h index 26ae6c7fc..0f0661172 100644 --- a/src/common/bit_field.h +++ b/src/common/bit_field.h | |||
| @@ -36,13 +36,6 @@ | |||
| 36 | #include "common/common_funcs.h" | 36 | #include "common/common_funcs.h" |
| 37 | #include "common/swap.h" | 37 | #include "common/swap.h" |
| 38 | 38 | ||
| 39 | // Inlining | ||
| 40 | #ifdef _WIN32 | ||
| 41 | #define FORCE_INLINE __forceinline | ||
| 42 | #else | ||
| 43 | #define FORCE_INLINE inline __attribute__((always_inline)) | ||
| 44 | #endif | ||
| 45 | |||
| 46 | /* | 39 | /* |
| 47 | * Abstract bitfield class | 40 | * Abstract bitfield class |
| 48 | * | 41 | * |
| @@ -142,8 +135,8 @@ public: | |||
| 142 | * containing several bitfields can be assembled by formatting each of their values and ORing | 135 | * containing several bitfields can be assembled by formatting each of their values and ORing |
| 143 | * the results together. | 136 | * the results together. |
| 144 | */ | 137 | */ |
| 145 | static constexpr FORCE_INLINE StorageType FormatValue(const T& value) { | 138 | [[nodiscard]] static constexpr StorageType FormatValue(const T& value) { |
| 146 | return ((StorageType)value << position) & mask; | 139 | return (static_cast<StorageType>(value) << position) & mask; |
| 147 | } | 140 | } |
| 148 | 141 | ||
| 149 | /** | 142 | /** |
| @@ -151,7 +144,7 @@ public: | |||
| 151 | * (such as Value() or operator T), but this can be used to extract a value from a bitfield | 144 | * (such as Value() or operator T), but this can be used to extract a value from a bitfield |
| 152 | * union in a constexpr context. | 145 | * union in a constexpr context. |
| 153 | */ | 146 | */ |
| 154 | static constexpr FORCE_INLINE T ExtractValue(const StorageType& storage) { | 147 | [[nodiscard]] static constexpr T ExtractValue(const StorageType& storage) { |
| 155 | if constexpr (std::numeric_limits<UnderlyingType>::is_signed) { | 148 | if constexpr (std::numeric_limits<UnderlyingType>::is_signed) { |
| 156 | std::size_t shift = 8 * sizeof(T) - bits; | 149 | std::size_t shift = 8 * sizeof(T) - bits; |
| 157 | return static_cast<T>(static_cast<UnderlyingType>(storage << (shift - position)) >> | 150 | return static_cast<T>(static_cast<UnderlyingType>(storage << (shift - position)) >> |
| @@ -175,7 +168,7 @@ public: | |||
| 175 | constexpr BitField(BitField&&) noexcept = default; | 168 | constexpr BitField(BitField&&) noexcept = default; |
| 176 | constexpr BitField& operator=(BitField&&) noexcept = default; | 169 | constexpr BitField& operator=(BitField&&) noexcept = default; |
| 177 | 170 | ||
| 178 | constexpr operator T() const { | 171 | [[nodiscard]] constexpr operator T() const { |
| 179 | return Value(); | 172 | return Value(); |
| 180 | } | 173 | } |
| 181 | 174 | ||
| @@ -183,11 +176,11 @@ public: | |||
| 183 | storage = static_cast<StorageType>((storage & ~mask) | FormatValue(value)); | 176 | storage = static_cast<StorageType>((storage & ~mask) | FormatValue(value)); |
| 184 | } | 177 | } |
| 185 | 178 | ||
| 186 | constexpr T Value() const { | 179 | [[nodiscard]] constexpr T Value() const { |
| 187 | return ExtractValue(storage); | 180 | return ExtractValue(storage); |
| 188 | } | 181 | } |
| 189 | 182 | ||
| 190 | constexpr explicit operator bool() const { | 183 | [[nodiscard]] constexpr explicit operator bool() const { |
| 191 | return Value() != 0; | 184 | return Value() != 0; |
| 192 | } | 185 | } |
| 193 | 186 | ||
diff --git a/src/common/bit_util.h b/src/common/bit_util.h index 6f7d5a947..29f59a9a3 100644 --- a/src/common/bit_util.h +++ b/src/common/bit_util.h | |||
| @@ -17,12 +17,12 @@ namespace Common { | |||
| 17 | 17 | ||
| 18 | /// Gets the size of a specified type T in bits. | 18 | /// Gets the size of a specified type T in bits. |
| 19 | template <typename T> | 19 | template <typename T> |
| 20 | constexpr std::size_t BitSize() { | 20 | [[nodiscard]] constexpr std::size_t BitSize() { |
| 21 | return sizeof(T) * CHAR_BIT; | 21 | return sizeof(T) * CHAR_BIT; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | #ifdef _MSC_VER | 24 | #ifdef _MSC_VER |
| 25 | inline u32 CountLeadingZeroes32(u32 value) { | 25 | [[nodiscard]] inline u32 CountLeadingZeroes32(u32 value) { |
| 26 | unsigned long leading_zero = 0; | 26 | unsigned long leading_zero = 0; |
| 27 | 27 | ||
| 28 | if (_BitScanReverse(&leading_zero, value) != 0) { | 28 | if (_BitScanReverse(&leading_zero, value) != 0) { |
| @@ -32,7 +32,7 @@ inline u32 CountLeadingZeroes32(u32 value) { | |||
| 32 | return 32; | 32 | return 32; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | inline u32 CountLeadingZeroes64(u64 value) { | 35 | [[nodiscard]] inline u32 CountLeadingZeroes64(u64 value) { |
| 36 | unsigned long leading_zero = 0; | 36 | unsigned long leading_zero = 0; |
| 37 | 37 | ||
| 38 | if (_BitScanReverse64(&leading_zero, value) != 0) { | 38 | if (_BitScanReverse64(&leading_zero, value) != 0) { |
| @@ -42,7 +42,7 @@ inline u32 CountLeadingZeroes64(u64 value) { | |||
| 42 | return 64; | 42 | return 64; |
| 43 | } | 43 | } |
| 44 | #else | 44 | #else |
| 45 | inline u32 CountLeadingZeroes32(u32 value) { | 45 | [[nodiscard]] inline u32 CountLeadingZeroes32(u32 value) { |
| 46 | if (value == 0) { | 46 | if (value == 0) { |
| 47 | return 32; | 47 | return 32; |
| 48 | } | 48 | } |
| @@ -50,7 +50,7 @@ inline u32 CountLeadingZeroes32(u32 value) { | |||
| 50 | return static_cast<u32>(__builtin_clz(value)); | 50 | return static_cast<u32>(__builtin_clz(value)); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | inline u32 CountLeadingZeroes64(u64 value) { | 53 | [[nodiscard]] inline u32 CountLeadingZeroes64(u64 value) { |
| 54 | if (value == 0) { | 54 | if (value == 0) { |
| 55 | return 64; | 55 | return 64; |
| 56 | } | 56 | } |
| @@ -60,7 +60,7 @@ inline u32 CountLeadingZeroes64(u64 value) { | |||
| 60 | #endif | 60 | #endif |
| 61 | 61 | ||
| 62 | #ifdef _MSC_VER | 62 | #ifdef _MSC_VER |
| 63 | inline u32 CountTrailingZeroes32(u32 value) { | 63 | [[nodiscard]] inline u32 CountTrailingZeroes32(u32 value) { |
| 64 | unsigned long trailing_zero = 0; | 64 | unsigned long trailing_zero = 0; |
| 65 | 65 | ||
| 66 | if (_BitScanForward(&trailing_zero, value) != 0) { | 66 | if (_BitScanForward(&trailing_zero, value) != 0) { |
| @@ -70,7 +70,7 @@ inline u32 CountTrailingZeroes32(u32 value) { | |||
| 70 | return 32; | 70 | return 32; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | inline u32 CountTrailingZeroes64(u64 value) { | 73 | [[nodiscard]] inline u32 CountTrailingZeroes64(u64 value) { |
| 74 | unsigned long trailing_zero = 0; | 74 | unsigned long trailing_zero = 0; |
| 75 | 75 | ||
| 76 | if (_BitScanForward64(&trailing_zero, value) != 0) { | 76 | if (_BitScanForward64(&trailing_zero, value) != 0) { |
| @@ -80,7 +80,7 @@ inline u32 CountTrailingZeroes64(u64 value) { | |||
| 80 | return 64; | 80 | return 64; |
| 81 | } | 81 | } |
| 82 | #else | 82 | #else |
| 83 | inline u32 CountTrailingZeroes32(u32 value) { | 83 | [[nodiscard]] inline u32 CountTrailingZeroes32(u32 value) { |
| 84 | if (value == 0) { | 84 | if (value == 0) { |
| 85 | return 32; | 85 | return 32; |
| 86 | } | 86 | } |
| @@ -88,7 +88,7 @@ inline u32 CountTrailingZeroes32(u32 value) { | |||
| 88 | return static_cast<u32>(__builtin_ctz(value)); | 88 | return static_cast<u32>(__builtin_ctz(value)); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | inline u32 CountTrailingZeroes64(u64 value) { | 91 | [[nodiscard]] inline u32 CountTrailingZeroes64(u64 value) { |
| 92 | if (value == 0) { | 92 | if (value == 0) { |
| 93 | return 64; | 93 | return 64; |
| 94 | } | 94 | } |
| @@ -99,13 +99,13 @@ inline u32 CountTrailingZeroes64(u64 value) { | |||
| 99 | 99 | ||
| 100 | #ifdef _MSC_VER | 100 | #ifdef _MSC_VER |
| 101 | 101 | ||
| 102 | inline u32 MostSignificantBit32(const u32 value) { | 102 | [[nodiscard]] inline u32 MostSignificantBit32(const u32 value) { |
| 103 | unsigned long result; | 103 | unsigned long result; |
| 104 | _BitScanReverse(&result, value); | 104 | _BitScanReverse(&result, value); |
| 105 | return static_cast<u32>(result); | 105 | return static_cast<u32>(result); |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | inline u32 MostSignificantBit64(const u64 value) { | 108 | [[nodiscard]] inline u32 MostSignificantBit64(const u64 value) { |
| 109 | unsigned long result; | 109 | unsigned long result; |
| 110 | _BitScanReverse64(&result, value); | 110 | _BitScanReverse64(&result, value); |
| 111 | return static_cast<u32>(result); | 111 | return static_cast<u32>(result); |
| @@ -113,30 +113,30 @@ inline u32 MostSignificantBit64(const u64 value) { | |||
| 113 | 113 | ||
| 114 | #else | 114 | #else |
| 115 | 115 | ||
| 116 | inline u32 MostSignificantBit32(const u32 value) { | 116 | [[nodiscard]] inline u32 MostSignificantBit32(const u32 value) { |
| 117 | return 31U - static_cast<u32>(__builtin_clz(value)); | 117 | return 31U - static_cast<u32>(__builtin_clz(value)); |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | inline u32 MostSignificantBit64(const u64 value) { | 120 | [[nodiscard]] inline u32 MostSignificantBit64(const u64 value) { |
| 121 | return 63U - static_cast<u32>(__builtin_clzll(value)); | 121 | return 63U - static_cast<u32>(__builtin_clzll(value)); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | #endif | 124 | #endif |
| 125 | 125 | ||
| 126 | inline u32 Log2Floor32(const u32 value) { | 126 | [[nodiscard]] inline u32 Log2Floor32(const u32 value) { |
| 127 | return MostSignificantBit32(value); | 127 | return MostSignificantBit32(value); |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | inline u32 Log2Ceil32(const u32 value) { | 130 | [[nodiscard]] inline u32 Log2Ceil32(const u32 value) { |
| 131 | const u32 log2_f = Log2Floor32(value); | 131 | const u32 log2_f = Log2Floor32(value); |
| 132 | return log2_f + ((value ^ (1U << log2_f)) != 0U); | 132 | return log2_f + ((value ^ (1U << log2_f)) != 0U); |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | inline u32 Log2Floor64(const u64 value) { | 135 | [[nodiscard]] inline u32 Log2Floor64(const u64 value) { |
| 136 | return MostSignificantBit64(value); | 136 | return MostSignificantBit64(value); |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | inline u32 Log2Ceil64(const u64 value) { | 139 | [[nodiscard]] inline u32 Log2Ceil64(const u64 value) { |
| 140 | const u64 log2_f = static_cast<u64>(Log2Floor64(value)); | 140 | const u64 log2_f = static_cast<u64>(Log2Floor64(value)); |
| 141 | return static_cast<u32>(log2_f + ((value ^ (1ULL << log2_f)) != 0ULL)); | 141 | return static_cast<u32>(log2_f + ((value ^ (1ULL << log2_f)) != 0ULL)); |
| 142 | } | 142 | } |
diff --git a/src/common/cityhash.h b/src/common/cityhash.h index 4b94f8e18..a00804e01 100644 --- a/src/common/cityhash.h +++ b/src/common/cityhash.h | |||
| @@ -61,42 +61,43 @@ | |||
| 61 | 61 | ||
| 62 | #pragma once | 62 | #pragma once |
| 63 | 63 | ||
| 64 | #include <cstddef> | ||
| 65 | #include <cstdint> | ||
| 64 | #include <utility> | 66 | #include <utility> |
| 65 | #include <stdint.h> | ||
| 66 | #include <stdlib.h> // for std::size_t. | ||
| 67 | 67 | ||
| 68 | namespace Common { | 68 | namespace Common { |
| 69 | 69 | ||
| 70 | typedef std::pair<uint64_t, uint64_t> uint128; | 70 | using uint128 = std::pair<uint64_t, uint64_t>; |
| 71 | 71 | ||
| 72 | inline uint64_t Uint128Low64(const uint128& x) { | 72 | [[nodiscard]] inline uint64_t Uint128Low64(const uint128& x) { |
| 73 | return x.first; | 73 | return x.first; |
| 74 | } | 74 | } |
| 75 | inline uint64_t Uint128High64(const uint128& x) { | 75 | [[nodiscard]] inline uint64_t Uint128High64(const uint128& x) { |
| 76 | return x.second; | 76 | return x.second; |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | // Hash function for a byte array. | 79 | // Hash function for a byte array. |
| 80 | uint64_t CityHash64(const char* buf, std::size_t len); | 80 | [[nodiscard]] uint64_t CityHash64(const char* buf, std::size_t len); |
| 81 | 81 | ||
| 82 | // Hash function for a byte array. For convenience, a 64-bit seed is also | 82 | // Hash function for a byte array. For convenience, a 64-bit seed is also |
| 83 | // hashed into the result. | 83 | // hashed into the result. |
| 84 | uint64_t CityHash64WithSeed(const char* buf, std::size_t len, uint64_t seed); | 84 | [[nodiscard]] uint64_t CityHash64WithSeed(const char* buf, std::size_t len, uint64_t seed); |
| 85 | 85 | ||
| 86 | // Hash function for a byte array. For convenience, two seeds are also | 86 | // Hash function for a byte array. For convenience, two seeds are also |
| 87 | // hashed into the result. | 87 | // hashed into the result. |
| 88 | uint64_t CityHash64WithSeeds(const char* buf, std::size_t len, uint64_t seed0, uint64_t seed1); | 88 | [[nodiscard]] uint64_t CityHash64WithSeeds(const char* buf, std::size_t len, uint64_t seed0, |
| 89 | uint64_t seed1); | ||
| 89 | 90 | ||
| 90 | // Hash function for a byte array. | 91 | // Hash function for a byte array. |
| 91 | uint128 CityHash128(const char* s, std::size_t len); | 92 | [[nodiscard]] uint128 CityHash128(const char* s, std::size_t len); |
| 92 | 93 | ||
| 93 | // Hash function for a byte array. For convenience, a 128-bit seed is also | 94 | // Hash function for a byte array. For convenience, a 128-bit seed is also |
| 94 | // hashed into the result. | 95 | // hashed into the result. |
| 95 | uint128 CityHash128WithSeed(const char* s, std::size_t len, uint128 seed); | 96 | [[nodiscard]] uint128 CityHash128WithSeed(const char* s, std::size_t len, uint128 seed); |
| 96 | 97 | ||
| 97 | // Hash 128 input bits down to 64 bits of output. | 98 | // Hash 128 input bits down to 64 bits of output. |
| 98 | // This is intended to be a reasonably good hash function. | 99 | // This is intended to be a reasonably good hash function. |
| 99 | inline uint64_t Hash128to64(const uint128& x) { | 100 | [[nodiscard]] inline uint64_t Hash128to64(const uint128& x) { |
| 100 | // Murmur-inspired hashing. | 101 | // Murmur-inspired hashing. |
| 101 | const uint64_t kMul = 0x9ddfea08eb382d69ULL; | 102 | const uint64_t kMul = 0x9ddfea08eb382d69ULL; |
| 102 | uint64_t a = (Uint128Low64(x) ^ Uint128High64(x)) * kMul; | 103 | uint64_t a = (Uint128Low64(x) ^ Uint128High64(x)) * kMul; |
diff --git a/src/common/color.h b/src/common/color.h index 3a2222077..381d6332e 100644 --- a/src/common/color.h +++ b/src/common/color.h | |||
| @@ -13,42 +13,42 @@ | |||
| 13 | namespace Color { | 13 | namespace Color { |
| 14 | 14 | ||
| 15 | /// Convert a 1-bit color component to 8 bit | 15 | /// Convert a 1-bit color component to 8 bit |
| 16 | constexpr u8 Convert1To8(u8 value) { | 16 | [[nodiscard]] constexpr u8 Convert1To8(u8 value) { |
| 17 | return value * 255; | 17 | return value * 255; |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | /// Convert a 4-bit color component to 8 bit | 20 | /// Convert a 4-bit color component to 8 bit |
| 21 | constexpr u8 Convert4To8(u8 value) { | 21 | [[nodiscard]] constexpr u8 Convert4To8(u8 value) { |
| 22 | return (value << 4) | value; | 22 | return (value << 4) | value; |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | /// Convert a 5-bit color component to 8 bit | 25 | /// Convert a 5-bit color component to 8 bit |
| 26 | constexpr u8 Convert5To8(u8 value) { | 26 | [[nodiscard]] constexpr u8 Convert5To8(u8 value) { |
| 27 | return (value << 3) | (value >> 2); | 27 | return (value << 3) | (value >> 2); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | /// Convert a 6-bit color component to 8 bit | 30 | /// Convert a 6-bit color component to 8 bit |
| 31 | constexpr u8 Convert6To8(u8 value) { | 31 | [[nodiscard]] constexpr u8 Convert6To8(u8 value) { |
| 32 | return (value << 2) | (value >> 4); | 32 | return (value << 2) | (value >> 4); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | /// Convert a 8-bit color component to 1 bit | 35 | /// Convert a 8-bit color component to 1 bit |
| 36 | constexpr u8 Convert8To1(u8 value) { | 36 | [[nodiscard]] constexpr u8 Convert8To1(u8 value) { |
| 37 | return value >> 7; | 37 | return value >> 7; |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | /// Convert a 8-bit color component to 4 bit | 40 | /// Convert a 8-bit color component to 4 bit |
| 41 | constexpr u8 Convert8To4(u8 value) { | 41 | [[nodiscard]] constexpr u8 Convert8To4(u8 value) { |
| 42 | return value >> 4; | 42 | return value >> 4; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | /// Convert a 8-bit color component to 5 bit | 45 | /// Convert a 8-bit color component to 5 bit |
| 46 | constexpr u8 Convert8To5(u8 value) { | 46 | [[nodiscard]] constexpr u8 Convert8To5(u8 value) { |
| 47 | return value >> 3; | 47 | return value >> 3; |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | /// Convert a 8-bit color component to 6 bit | 50 | /// Convert a 8-bit color component to 6 bit |
| 51 | constexpr u8 Convert8To6(u8 value) { | 51 | [[nodiscard]] constexpr u8 Convert8To6(u8 value) { |
| 52 | return value >> 2; | 52 | return value >> 2; |
| 53 | } | 53 | } |
| 54 | 54 | ||
| @@ -57,7 +57,7 @@ constexpr u8 Convert8To6(u8 value) { | |||
| 57 | * @param bytes Pointer to encoded source color | 57 | * @param bytes Pointer to encoded source color |
| 58 | * @return Result color decoded as Common::Vec4<u8> | 58 | * @return Result color decoded as Common::Vec4<u8> |
| 59 | */ | 59 | */ |
| 60 | inline Common::Vec4<u8> DecodeRGBA8(const u8* bytes) { | 60 | [[nodiscard]] inline Common::Vec4<u8> DecodeRGBA8(const u8* bytes) { |
| 61 | return {bytes[3], bytes[2], bytes[1], bytes[0]}; | 61 | return {bytes[3], bytes[2], bytes[1], bytes[0]}; |
| 62 | } | 62 | } |
| 63 | 63 | ||
| @@ -66,7 +66,7 @@ inline Common::Vec4<u8> DecodeRGBA8(const u8* bytes) { | |||
| 66 | * @param bytes Pointer to encoded source color | 66 | * @param bytes Pointer to encoded source color |
| 67 | * @return Result color decoded as Common::Vec4<u8> | 67 | * @return Result color decoded as Common::Vec4<u8> |
| 68 | */ | 68 | */ |
| 69 | inline Common::Vec4<u8> DecodeRGB8(const u8* bytes) { | 69 | [[nodiscard]] inline Common::Vec4<u8> DecodeRGB8(const u8* bytes) { |
| 70 | return {bytes[2], bytes[1], bytes[0], 255}; | 70 | return {bytes[2], bytes[1], bytes[0], 255}; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| @@ -75,7 +75,7 @@ inline Common::Vec4<u8> DecodeRGB8(const u8* bytes) { | |||
| 75 | * @param bytes Pointer to encoded source color | 75 | * @param bytes Pointer to encoded source color |
| 76 | * @return Result color decoded as Common::Vec4<u8> | 76 | * @return Result color decoded as Common::Vec4<u8> |
| 77 | */ | 77 | */ |
| 78 | inline Common::Vec4<u8> DecodeRG8(const u8* bytes) { | 78 | [[nodiscard]] inline Common::Vec4<u8> DecodeRG8(const u8* bytes) { |
| 79 | return {bytes[1], bytes[0], 0, 255}; | 79 | return {bytes[1], bytes[0], 0, 255}; |
| 80 | } | 80 | } |
| 81 | 81 | ||
| @@ -84,7 +84,7 @@ inline Common::Vec4<u8> DecodeRG8(const u8* bytes) { | |||
| 84 | * @param bytes Pointer to encoded source color | 84 | * @param bytes Pointer to encoded source color |
| 85 | * @return Result color decoded as Common::Vec4<u8> | 85 | * @return Result color decoded as Common::Vec4<u8> |
| 86 | */ | 86 | */ |
| 87 | inline Common::Vec4<u8> DecodeRGB565(const u8* bytes) { | 87 | [[nodiscard]] inline Common::Vec4<u8> DecodeRGB565(const u8* bytes) { |
| 88 | u16_le pixel; | 88 | u16_le pixel; |
| 89 | std::memcpy(&pixel, bytes, sizeof(pixel)); | 89 | std::memcpy(&pixel, bytes, sizeof(pixel)); |
| 90 | return {Convert5To8((pixel >> 11) & 0x1F), Convert6To8((pixel >> 5) & 0x3F), | 90 | return {Convert5To8((pixel >> 11) & 0x1F), Convert6To8((pixel >> 5) & 0x3F), |
| @@ -96,7 +96,7 @@ inline Common::Vec4<u8> DecodeRGB565(const u8* bytes) { | |||
| 96 | * @param bytes Pointer to encoded source color | 96 | * @param bytes Pointer to encoded source color |
| 97 | * @return Result color decoded as Common::Vec4<u8> | 97 | * @return Result color decoded as Common::Vec4<u8> |
| 98 | */ | 98 | */ |
| 99 | inline Common::Vec4<u8> DecodeRGB5A1(const u8* bytes) { | 99 | [[nodiscard]] inline Common::Vec4<u8> DecodeRGB5A1(const u8* bytes) { |
| 100 | u16_le pixel; | 100 | u16_le pixel; |
| 101 | std::memcpy(&pixel, bytes, sizeof(pixel)); | 101 | std::memcpy(&pixel, bytes, sizeof(pixel)); |
| 102 | return {Convert5To8((pixel >> 11) & 0x1F), Convert5To8((pixel >> 6) & 0x1F), | 102 | return {Convert5To8((pixel >> 11) & 0x1F), Convert5To8((pixel >> 6) & 0x1F), |
| @@ -108,7 +108,7 @@ inline Common::Vec4<u8> DecodeRGB5A1(const u8* bytes) { | |||
| 108 | * @param bytes Pointer to encoded source color | 108 | * @param bytes Pointer to encoded source color |
| 109 | * @return Result color decoded as Common::Vec4<u8> | 109 | * @return Result color decoded as Common::Vec4<u8> |
| 110 | */ | 110 | */ |
| 111 | inline Common::Vec4<u8> DecodeRGBA4(const u8* bytes) { | 111 | [[nodiscard]] inline Common::Vec4<u8> DecodeRGBA4(const u8* bytes) { |
| 112 | u16_le pixel; | 112 | u16_le pixel; |
| 113 | std::memcpy(&pixel, bytes, sizeof(pixel)); | 113 | std::memcpy(&pixel, bytes, sizeof(pixel)); |
| 114 | return {Convert4To8((pixel >> 12) & 0xF), Convert4To8((pixel >> 8) & 0xF), | 114 | return {Convert4To8((pixel >> 12) & 0xF), Convert4To8((pixel >> 8) & 0xF), |
| @@ -120,7 +120,7 @@ inline Common::Vec4<u8> DecodeRGBA4(const u8* bytes) { | |||
| 120 | * @param bytes Pointer to encoded source value | 120 | * @param bytes Pointer to encoded source value |
| 121 | * @return Depth value as an u32 | 121 | * @return Depth value as an u32 |
| 122 | */ | 122 | */ |
| 123 | inline u32 DecodeD16(const u8* bytes) { | 123 | [[nodiscard]] inline u32 DecodeD16(const u8* bytes) { |
| 124 | u16_le data; | 124 | u16_le data; |
| 125 | std::memcpy(&data, bytes, sizeof(data)); | 125 | std::memcpy(&data, bytes, sizeof(data)); |
| 126 | return data; | 126 | return data; |
| @@ -131,7 +131,7 @@ inline u32 DecodeD16(const u8* bytes) { | |||
| 131 | * @param bytes Pointer to encoded source value | 131 | * @param bytes Pointer to encoded source value |
| 132 | * @return Depth value as an u32 | 132 | * @return Depth value as an u32 |
| 133 | */ | 133 | */ |
| 134 | inline u32 DecodeD24(const u8* bytes) { | 134 | [[nodiscard]] inline u32 DecodeD24(const u8* bytes) { |
| 135 | return (bytes[2] << 16) | (bytes[1] << 8) | bytes[0]; | 135 | return (bytes[2] << 16) | (bytes[1] << 8) | bytes[0]; |
| 136 | } | 136 | } |
| 137 | 137 | ||
| @@ -140,7 +140,7 @@ inline u32 DecodeD24(const u8* bytes) { | |||
| 140 | * @param bytes Pointer to encoded source values | 140 | * @param bytes Pointer to encoded source values |
| 141 | * @return Resulting values stored as a Common::Vec2 | 141 | * @return Resulting values stored as a Common::Vec2 |
| 142 | */ | 142 | */ |
| 143 | inline Common::Vec2<u32> DecodeD24S8(const u8* bytes) { | 143 | [[nodiscard]] inline Common::Vec2<u32> DecodeD24S8(const u8* bytes) { |
| 144 | return {static_cast<u32>((bytes[2] << 16) | (bytes[1] << 8) | bytes[0]), bytes[3]}; | 144 | return {static_cast<u32>((bytes[2] << 16) | (bytes[1] << 8) | bytes[0]), bytes[3]}; |
| 145 | } | 145 | } |
| 146 | 146 | ||
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 88cf5250a..98421bced 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h | |||
| @@ -53,14 +53,14 @@ __declspec(dllimport) void __stdcall DebugBreak(void); | |||
| 53 | // Call directly after the command or use the error num. | 53 | // Call directly after the command or use the error num. |
| 54 | // This function might change the error code. | 54 | // This function might change the error code. |
| 55 | // Defined in Misc.cpp. | 55 | // Defined in Misc.cpp. |
| 56 | std::string GetLastErrorMsg(); | 56 | [[nodiscard]] std::string GetLastErrorMsg(); |
| 57 | 57 | ||
| 58 | #define DECLARE_ENUM_FLAG_OPERATORS(type) \ | 58 | #define DECLARE_ENUM_FLAG_OPERATORS(type) \ |
| 59 | constexpr type operator|(type a, type b) noexcept { \ | 59 | [[nodiscard]] constexpr type operator|(type a, type b) noexcept { \ |
| 60 | using T = std::underlying_type_t<type>; \ | 60 | using T = std::underlying_type_t<type>; \ |
| 61 | return static_cast<type>(static_cast<T>(a) | static_cast<T>(b)); \ | 61 | return static_cast<type>(static_cast<T>(a) | static_cast<T>(b)); \ |
| 62 | } \ | 62 | } \ |
| 63 | constexpr type operator&(type a, type b) noexcept { \ | 63 | [[nodiscard]] constexpr type operator&(type a, type b) noexcept { \ |
| 64 | using T = std::underlying_type_t<type>; \ | 64 | using T = std::underlying_type_t<type>; \ |
| 65 | return static_cast<type>(static_cast<T>(a) & static_cast<T>(b)); \ | 65 | return static_cast<type>(static_cast<T>(a) & static_cast<T>(b)); \ |
| 66 | } \ | 66 | } \ |
| @@ -74,22 +74,22 @@ std::string GetLastErrorMsg(); | |||
| 74 | a = static_cast<type>(static_cast<T>(a) & static_cast<T>(b)); \ | 74 | a = static_cast<type>(static_cast<T>(a) & static_cast<T>(b)); \ |
| 75 | return a; \ | 75 | return a; \ |
| 76 | } \ | 76 | } \ |
| 77 | constexpr type operator~(type key) noexcept { \ | 77 | [[nodiscard]] constexpr type operator~(type key) noexcept { \ |
| 78 | using T = std::underlying_type_t<type>; \ | 78 | using T = std::underlying_type_t<type>; \ |
| 79 | return static_cast<type>(~static_cast<T>(key)); \ | 79 | return static_cast<type>(~static_cast<T>(key)); \ |
| 80 | } \ | 80 | } \ |
| 81 | constexpr bool True(type key) noexcept { \ | 81 | [[nodiscard]] constexpr bool True(type key) noexcept { \ |
| 82 | using T = std::underlying_type_t<type>; \ | 82 | using T = std::underlying_type_t<type>; \ |
| 83 | return static_cast<T>(key) != 0; \ | 83 | return static_cast<T>(key) != 0; \ |
| 84 | } \ | 84 | } \ |
| 85 | constexpr bool False(type key) noexcept { \ | 85 | [[nodiscard]] constexpr bool False(type key) noexcept { \ |
| 86 | using T = std::underlying_type_t<type>; \ | 86 | using T = std::underlying_type_t<type>; \ |
| 87 | return static_cast<T>(key) == 0; \ | 87 | return static_cast<T>(key) == 0; \ |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | namespace Common { | 90 | namespace Common { |
| 91 | 91 | ||
| 92 | constexpr u32 MakeMagic(char a, char b, char c, char d) { | 92 | [[nodiscard]] constexpr u32 MakeMagic(char a, char b, char c, char d) { |
| 93 | return u32(a) | u32(b) << 8 | u32(c) << 16 | u32(d) << 24; | 93 | return u32(a) | u32(b) << 8 | u32(c) << 16 | u32(d) << 24; |
| 94 | } | 94 | } |
| 95 | 95 | ||
diff --git a/src/common/dynamic_library.h b/src/common/dynamic_library.h index 2a06372fd..3512da940 100644 --- a/src/common/dynamic_library.h +++ b/src/common/dynamic_library.h | |||
| @@ -33,7 +33,7 @@ public: | |||
| 33 | ~DynamicLibrary(); | 33 | ~DynamicLibrary(); |
| 34 | 34 | ||
| 35 | /// Returns the specified library name with the platform-specific suffix added. | 35 | /// Returns the specified library name with the platform-specific suffix added. |
| 36 | static std::string GetUnprefixedFilename(const char* filename); | 36 | [[nodiscard]] static std::string GetUnprefixedFilename(const char* filename); |
| 37 | 37 | ||
| 38 | /// Returns the specified library name in platform-specific format. | 38 | /// Returns the specified library name in platform-specific format. |
| 39 | /// Major/minor versions will not be included if set to -1. | 39 | /// Major/minor versions will not be included if set to -1. |
| @@ -41,28 +41,29 @@ public: | |||
| 41 | /// Windows: LIBNAME-MAJOR-MINOR.dll | 41 | /// Windows: LIBNAME-MAJOR-MINOR.dll |
| 42 | /// Linux: libLIBNAME.so.MAJOR.MINOR | 42 | /// Linux: libLIBNAME.so.MAJOR.MINOR |
| 43 | /// Mac: libLIBNAME.MAJOR.MINOR.dylib | 43 | /// Mac: libLIBNAME.MAJOR.MINOR.dylib |
| 44 | static std::string GetVersionedFilename(const char* libname, int major = -1, int minor = -1); | 44 | [[nodiscard]] static std::string GetVersionedFilename(const char* libname, int major = -1, |
| 45 | int minor = -1); | ||
| 45 | 46 | ||
| 46 | /// Returns true if a module is loaded, otherwise false. | 47 | /// Returns true if a module is loaded, otherwise false. |
| 47 | bool IsOpen() const { | 48 | [[nodiscard]] bool IsOpen() const { |
| 48 | return handle != nullptr; | 49 | return handle != nullptr; |
| 49 | } | 50 | } |
| 50 | 51 | ||
| 51 | /// Loads (or replaces) the handle with the specified library file name. | 52 | /// Loads (or replaces) the handle with the specified library file name. |
| 52 | /// Returns true if the library was loaded and can be used. | 53 | /// Returns true if the library was loaded and can be used. |
| 53 | bool Open(const char* filename); | 54 | [[nodiscard]] bool Open(const char* filename); |
| 54 | 55 | ||
| 55 | /// Unloads the library, any function pointers from this library are no longer valid. | 56 | /// Unloads the library, any function pointers from this library are no longer valid. |
| 56 | void Close(); | 57 | void Close(); |
| 57 | 58 | ||
| 58 | /// Returns the address of the specified symbol (function or variable) as an untyped pointer. | 59 | /// Returns the address of the specified symbol (function or variable) as an untyped pointer. |
| 59 | /// If the specified symbol does not exist in this library, nullptr is returned. | 60 | /// If the specified symbol does not exist in this library, nullptr is returned. |
| 60 | void* GetSymbolAddress(const char* name) const; | 61 | [[nodiscard]] void* GetSymbolAddress(const char* name) const; |
| 61 | 62 | ||
| 62 | /// Obtains the address of the specified symbol, automatically casting to the correct type. | 63 | /// Obtains the address of the specified symbol, automatically casting to the correct type. |
| 63 | /// Returns true if the symbol was found and assigned, otherwise false. | 64 | /// Returns true if the symbol was found and assigned, otherwise false. |
| 64 | template <typename T> | 65 | template <typename T> |
| 65 | bool GetSymbol(const char* name, T* ptr) const { | 66 | [[nodiscard]] bool GetSymbol(const char* name, T* ptr) const { |
| 66 | *ptr = reinterpret_cast<T>(GetSymbolAddress(name)); | 67 | *ptr = reinterpret_cast<T>(GetSymbolAddress(name)); |
| 67 | return *ptr != nullptr; | 68 | return *ptr != nullptr; |
| 68 | } | 69 | } |
diff --git a/src/common/fiber.h b/src/common/fiber.h index dafc1100e..89dde5e36 100644 --- a/src/common/fiber.h +++ b/src/common/fiber.h | |||
| @@ -47,7 +47,7 @@ public: | |||
| 47 | /// Yields control from Fiber 'from' to Fiber 'to' | 47 | /// Yields control from Fiber 'from' to Fiber 'to' |
| 48 | /// Fiber 'from' must be the currently running fiber. | 48 | /// Fiber 'from' must be the currently running fiber. |
| 49 | static void YieldTo(std::shared_ptr<Fiber>& from, std::shared_ptr<Fiber>& to); | 49 | static void YieldTo(std::shared_ptr<Fiber>& from, std::shared_ptr<Fiber>& to); |
| 50 | static std::shared_ptr<Fiber> ThreadToFiber(); | 50 | [[nodiscard]] static std::shared_ptr<Fiber> ThreadToFiber(); |
| 51 | 51 | ||
| 52 | void SetRewindPoint(std::function<void(void*)>&& rewind_func, void* start_parameter); | 52 | void SetRewindPoint(std::function<void(void*)>&& rewind_func, void* start_parameter); |
| 53 | 53 | ||
diff --git a/src/common/file_util.h b/src/common/file_util.h index 187b93161..681b28137 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h | |||
| @@ -48,19 +48,19 @@ struct FSTEntry { | |||
| 48 | }; | 48 | }; |
| 49 | 49 | ||
| 50 | // Returns true if file filename exists | 50 | // Returns true if file filename exists |
| 51 | bool Exists(const std::string& filename); | 51 | [[nodiscard]] bool Exists(const std::string& filename); |
| 52 | 52 | ||
| 53 | // Returns true if filename is a directory | 53 | // Returns true if filename is a directory |
| 54 | bool IsDirectory(const std::string& filename); | 54 | [[nodiscard]] bool IsDirectory(const std::string& filename); |
| 55 | 55 | ||
| 56 | // Returns the size of filename (64bit) | 56 | // Returns the size of filename (64bit) |
| 57 | u64 GetSize(const std::string& filename); | 57 | [[nodiscard]] u64 GetSize(const std::string& filename); |
| 58 | 58 | ||
| 59 | // Overloaded GetSize, accepts file descriptor | 59 | // Overloaded GetSize, accepts file descriptor |
| 60 | u64 GetSize(const int fd); | 60 | [[nodiscard]] u64 GetSize(int fd); |
| 61 | 61 | ||
| 62 | // Overloaded GetSize, accepts FILE* | 62 | // Overloaded GetSize, accepts FILE* |
| 63 | u64 GetSize(FILE* f); | 63 | [[nodiscard]] u64 GetSize(FILE* f); |
| 64 | 64 | ||
| 65 | // Returns true if successful, or path already exists. | 65 | // Returns true if successful, or path already exists. |
| 66 | bool CreateDir(const std::string& filename); | 66 | bool CreateDir(const std::string& filename); |
| @@ -120,7 +120,7 @@ u64 ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry, | |||
| 120 | bool DeleteDirRecursively(const std::string& directory, unsigned int recursion = 256); | 120 | bool DeleteDirRecursively(const std::string& directory, unsigned int recursion = 256); |
| 121 | 121 | ||
| 122 | // Returns the current directory | 122 | // Returns the current directory |
| 123 | std::optional<std::string> GetCurrentDir(); | 123 | [[nodiscard]] std::optional<std::string> GetCurrentDir(); |
| 124 | 124 | ||
| 125 | // Create directory and copy contents (does not overwrite existing files) | 125 | // Create directory and copy contents (does not overwrite existing files) |
| 126 | void CopyDir(const std::string& source_path, const std::string& dest_path); | 126 | void CopyDir(const std::string& source_path, const std::string& dest_path); |
| @@ -132,20 +132,20 @@ bool SetCurrentDir(const std::string& directory); | |||
| 132 | // directory. To be used in "multi-user" mode (that is, installed). | 132 | // directory. To be used in "multi-user" mode (that is, installed). |
| 133 | const std::string& GetUserPath(UserPath path, const std::string& new_path = ""); | 133 | const std::string& GetUserPath(UserPath path, const std::string& new_path = ""); |
| 134 | 134 | ||
| 135 | std::string GetHactoolConfigurationPath(); | 135 | [[nodiscard]] std::string GetHactoolConfigurationPath(); |
| 136 | 136 | ||
| 137 | std::string GetNANDRegistrationDir(bool system = false); | 137 | [[nodiscard]] std::string GetNANDRegistrationDir(bool system = false); |
| 138 | 138 | ||
| 139 | // Returns the path to where the sys file are | 139 | // Returns the path to where the sys file are |
| 140 | std::string GetSysDirectory(); | 140 | [[nodiscard]] std::string GetSysDirectory(); |
| 141 | 141 | ||
| 142 | #ifdef __APPLE__ | 142 | #ifdef __APPLE__ |
| 143 | std::string GetBundleDirectory(); | 143 | [[nodiscard]] std::string GetBundleDirectory(); |
| 144 | #endif | 144 | #endif |
| 145 | 145 | ||
| 146 | #ifdef _WIN32 | 146 | #ifdef _WIN32 |
| 147 | const std::string& GetExeDirectory(); | 147 | [[nodiscard]] const std::string& GetExeDirectory(); |
| 148 | std::string AppDataRoamingDirectory(); | 148 | [[nodiscard]] std::string AppDataRoamingDirectory(); |
| 149 | #endif | 149 | #endif |
| 150 | 150 | ||
| 151 | std::size_t WriteStringToFile(bool text_file, const std::string& filename, std::string_view str); | 151 | std::size_t WriteStringToFile(bool text_file, const std::string& filename, std::string_view str); |
| @@ -164,38 +164,45 @@ void SplitFilename83(const std::string& filename, std::array<char, 9>& short_nam | |||
| 164 | 164 | ||
| 165 | // Splits the path on '/' or '\' and put the components into a vector | 165 | // Splits the path on '/' or '\' and put the components into a vector |
| 166 | // i.e. "C:\Users\Yuzu\Documents\save.bin" becomes {"C:", "Users", "Yuzu", "Documents", "save.bin" } | 166 | // i.e. "C:\Users\Yuzu\Documents\save.bin" becomes {"C:", "Users", "Yuzu", "Documents", "save.bin" } |
| 167 | std::vector<std::string> SplitPathComponents(std::string_view filename); | 167 | [[nodiscard]] std::vector<std::string> SplitPathComponents(std::string_view filename); |
| 168 | 168 | ||
| 169 | // Gets all of the text up to the last '/' or '\' in the path. | 169 | // Gets all of the text up to the last '/' or '\' in the path. |
| 170 | std::string_view GetParentPath(std::string_view path); | 170 | [[nodiscard]] std::string_view GetParentPath(std::string_view path); |
| 171 | 171 | ||
| 172 | // Gets all of the text after the first '/' or '\' in the path. | 172 | // Gets all of the text after the first '/' or '\' in the path. |
| 173 | std::string_view GetPathWithoutTop(std::string_view path); | 173 | [[nodiscard]] std::string_view GetPathWithoutTop(std::string_view path); |
| 174 | 174 | ||
| 175 | // Gets the filename of the path | 175 | // Gets the filename of the path |
| 176 | std::string_view GetFilename(std::string_view path); | 176 | [[nodiscard]] std::string_view GetFilename(std::string_view path); |
| 177 | 177 | ||
| 178 | // Gets the extension of the filename | 178 | // Gets the extension of the filename |
| 179 | std::string_view GetExtensionFromFilename(std::string_view name); | 179 | [[nodiscard]] std::string_view GetExtensionFromFilename(std::string_view name); |
| 180 | 180 | ||
| 181 | // Removes the final '/' or '\' if one exists | 181 | // Removes the final '/' or '\' if one exists |
| 182 | std::string_view RemoveTrailingSlash(std::string_view path); | 182 | [[nodiscard]] std::string_view RemoveTrailingSlash(std::string_view path); |
| 183 | 183 | ||
| 184 | // Creates a new vector containing indices [first, last) from the original. | 184 | // Creates a new vector containing indices [first, last) from the original. |
| 185 | template <typename T> | 185 | template <typename T> |
| 186 | std::vector<T> SliceVector(const std::vector<T>& vector, std::size_t first, std::size_t last) { | 186 | [[nodiscard]] std::vector<T> SliceVector(const std::vector<T>& vector, std::size_t first, |
| 187 | if (first >= last) | 187 | std::size_t last) { |
| 188 | if (first >= last) { | ||
| 188 | return {}; | 189 | return {}; |
| 190 | } | ||
| 189 | last = std::min<std::size_t>(last, vector.size()); | 191 | last = std::min<std::size_t>(last, vector.size()); |
| 190 | return std::vector<T>(vector.begin() + first, vector.begin() + first + last); | 192 | return std::vector<T>(vector.begin() + first, vector.begin() + first + last); |
| 191 | } | 193 | } |
| 192 | 194 | ||
| 193 | enum class DirectorySeparator { ForwardSlash, BackwardSlash, PlatformDefault }; | 195 | enum class DirectorySeparator { |
| 196 | ForwardSlash, | ||
| 197 | BackwardSlash, | ||
| 198 | PlatformDefault, | ||
| 199 | }; | ||
| 194 | 200 | ||
| 195 | // Removes trailing slash, makes all '\\' into '/', and removes duplicate '/'. Makes '/' into '\\' | 201 | // Removes trailing slash, makes all '\\' into '/', and removes duplicate '/'. Makes '/' into '\\' |
| 196 | // depending if directory_separator is BackwardSlash or PlatformDefault and running on windows | 202 | // depending if directory_separator is BackwardSlash or PlatformDefault and running on windows |
| 197 | std::string SanitizePath(std::string_view path, | 203 | [[nodiscard]] std::string SanitizePath( |
| 198 | DirectorySeparator directory_separator = DirectorySeparator::ForwardSlash); | 204 | std::string_view path, |
| 205 | DirectorySeparator directory_separator = DirectorySeparator::ForwardSlash); | ||
| 199 | 206 | ||
| 200 | // simple wrapper for cstdlib file functions to | 207 | // simple wrapper for cstdlib file functions to |
| 201 | // hopefully will make error checking easier | 208 | // hopefully will make error checking easier |
| @@ -215,7 +222,7 @@ public: | |||
| 215 | 222 | ||
| 216 | void Swap(IOFile& other) noexcept; | 223 | void Swap(IOFile& other) noexcept; |
| 217 | 224 | ||
| 218 | bool Open(const std::string& filename, const char openmode[], int flags = 0); | 225 | [[nodiscard]] bool Open(const std::string& filename, const char openmode[], int flags = 0); |
| 219 | bool Close(); | 226 | bool Close(); |
| 220 | 227 | ||
| 221 | template <typename T> | 228 | template <typename T> |
| @@ -256,13 +263,13 @@ public: | |||
| 256 | return WriteArray(str.data(), str.length()); | 263 | return WriteArray(str.data(), str.length()); |
| 257 | } | 264 | } |
| 258 | 265 | ||
| 259 | bool IsOpen() const { | 266 | [[nodiscard]] bool IsOpen() const { |
| 260 | return nullptr != m_file; | 267 | return nullptr != m_file; |
| 261 | } | 268 | } |
| 262 | 269 | ||
| 263 | bool Seek(s64 off, int origin) const; | 270 | bool Seek(s64 off, int origin) const; |
| 264 | u64 Tell() const; | 271 | [[nodiscard]] u64 Tell() const; |
| 265 | u64 GetSize() const; | 272 | [[nodiscard]] u64 GetSize() const; |
| 266 | bool Resize(u64 size); | 273 | bool Resize(u64 size); |
| 267 | bool Flush(); | 274 | bool Flush(); |
| 268 | 275 | ||
diff --git a/src/common/hash.h b/src/common/hash.h index b2538f3ea..298930702 100644 --- a/src/common/hash.h +++ b/src/common/hash.h | |||
| @@ -5,36 +5,11 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <cstddef> | 7 | #include <cstddef> |
| 8 | #include <cstring> | ||
| 9 | #include <utility> | 8 | #include <utility> |
| 10 | #include <boost/functional/hash.hpp> | 9 | #include <boost/functional/hash.hpp> |
| 11 | #include "common/cityhash.h" | ||
| 12 | #include "common/common_types.h" | ||
| 13 | 10 | ||
| 14 | namespace Common { | 11 | namespace Common { |
| 15 | 12 | ||
| 16 | /** | ||
| 17 | * Computes a 64-bit hash over the specified block of data | ||
| 18 | * @param data Block of data to compute hash over | ||
| 19 | * @param len Length of data (in bytes) to compute hash over | ||
| 20 | * @returns 64-bit hash value that was computed over the data block | ||
| 21 | */ | ||
| 22 | static inline u64 ComputeHash64(const void* data, std::size_t len) { | ||
| 23 | return CityHash64(static_cast<const char*>(data), len); | ||
| 24 | } | ||
| 25 | |||
| 26 | /** | ||
| 27 | * Computes a 64-bit hash of a struct. In addition to being trivially copyable, it is also critical | ||
| 28 | * that either the struct includes no padding, or that any padding is initialized to a known value | ||
| 29 | * by memsetting the struct to 0 before filling it in. | ||
| 30 | */ | ||
| 31 | template <typename T> | ||
| 32 | static inline u64 ComputeStructHash64(const T& data) { | ||
| 33 | static_assert(std::is_trivially_copyable_v<T>, | ||
| 34 | "Type passed to ComputeStructHash64 must be trivially copyable"); | ||
| 35 | return ComputeHash64(&data, sizeof(data)); | ||
| 36 | } | ||
| 37 | |||
| 38 | struct PairHash { | 13 | struct PairHash { |
| 39 | template <class T1, class T2> | 14 | template <class T1, class T2> |
| 40 | std::size_t operator()(const std::pair<T1, T2>& pair) const noexcept { | 15 | std::size_t operator()(const std::pair<T1, T2>& pair) const noexcept { |
diff --git a/src/common/hex_util.h b/src/common/hex_util.h index a0a0e78a4..120f1a5e6 100644 --- a/src/common/hex_util.h +++ b/src/common/hex_util.h | |||
| @@ -14,7 +14,7 @@ | |||
| 14 | 14 | ||
| 15 | namespace Common { | 15 | namespace Common { |
| 16 | 16 | ||
| 17 | constexpr u8 ToHexNibble(char c) { | 17 | [[nodiscard]] constexpr u8 ToHexNibble(char c) { |
| 18 | if (c >= 65 && c <= 70) { | 18 | if (c >= 65 && c <= 70) { |
| 19 | return c - 55; | 19 | return c - 55; |
| 20 | } | 20 | } |
| @@ -26,10 +26,10 @@ constexpr u8 ToHexNibble(char c) { | |||
| 26 | return c - 48; | 26 | return c - 48; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | std::vector<u8> HexStringToVector(std::string_view str, bool little_endian); | 29 | [[nodiscard]] std::vector<u8> HexStringToVector(std::string_view str, bool little_endian); |
| 30 | 30 | ||
| 31 | template <std::size_t Size, bool le = false> | 31 | template <std::size_t Size, bool le = false> |
| 32 | constexpr std::array<u8, Size> HexStringToArray(std::string_view str) { | 32 | [[nodiscard]] constexpr std::array<u8, Size> HexStringToArray(std::string_view str) { |
| 33 | std::array<u8, Size> out{}; | 33 | std::array<u8, Size> out{}; |
| 34 | if constexpr (le) { | 34 | if constexpr (le) { |
| 35 | for (std::size_t i = 2 * Size - 2; i <= 2 * Size; i -= 2) { | 35 | for (std::size_t i = 2 * Size - 2; i <= 2 * Size; i -= 2) { |
| @@ -44,7 +44,7 @@ constexpr std::array<u8, Size> HexStringToArray(std::string_view str) { | |||
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | template <typename ContiguousContainer> | 46 | template <typename ContiguousContainer> |
| 47 | std::string HexToString(const ContiguousContainer& data, bool upper = true) { | 47 | [[nodiscard]] std::string HexToString(const ContiguousContainer& data, bool upper = true) { |
| 48 | static_assert(std::is_same_v<typename ContiguousContainer::value_type, u8>, | 48 | static_assert(std::is_same_v<typename ContiguousContainer::value_type, u8>, |
| 49 | "Underlying type within the contiguous container must be u8."); | 49 | "Underlying type within the contiguous container must be u8."); |
| 50 | 50 | ||
| @@ -60,11 +60,11 @@ std::string HexToString(const ContiguousContainer& data, bool upper = true) { | |||
| 60 | return out; | 60 | return out; |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | constexpr std::array<u8, 16> AsArray(const char (&data)[17]) { | 63 | [[nodiscard]] constexpr std::array<u8, 16> AsArray(const char (&data)[17]) { |
| 64 | return HexStringToArray<16>(data); | 64 | return HexStringToArray<16>(data); |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | constexpr std::array<u8, 32> AsArray(const char (&data)[65]) { | 67 | [[nodiscard]] constexpr std::array<u8, 32> AsArray(const char (&data)[65]) { |
| 68 | return HexStringToArray<32>(data); | 68 | return HexStringToArray<32>(data); |
| 69 | } | 69 | } |
| 70 | 70 | ||
diff --git a/src/common/lz4_compression.h b/src/common/lz4_compression.h index 173f9b9ad..088ff5c91 100644 --- a/src/common/lz4_compression.h +++ b/src/common/lz4_compression.h | |||
| @@ -18,7 +18,7 @@ namespace Common::Compression { | |||
| 18 | * | 18 | * |
| 19 | * @return the compressed data. | 19 | * @return the compressed data. |
| 20 | */ | 20 | */ |
| 21 | std::vector<u8> CompressDataLZ4(std::span<const u8> source); | 21 | [[nodiscard]] std::vector<u8> CompressDataLZ4(std::span<const u8> source); |
| 22 | 22 | ||
| 23 | /** | 23 | /** |
| 24 | * Utilizes the LZ4 subalgorithm LZ4HC with the specified compression level. Higher compression | 24 | * Utilizes the LZ4 subalgorithm LZ4HC with the specified compression level. Higher compression |
| @@ -31,7 +31,7 @@ std::vector<u8> CompressDataLZ4(std::span<const u8> source); | |||
| 31 | * | 31 | * |
| 32 | * @return the compressed data. | 32 | * @return the compressed data. |
| 33 | */ | 33 | */ |
| 34 | std::vector<u8> CompressDataLZ4HC(std::span<const u8> source, s32 compression_level); | 34 | [[nodiscard]] std::vector<u8> CompressDataLZ4HC(std::span<const u8> source, s32 compression_level); |
| 35 | 35 | ||
| 36 | /** | 36 | /** |
| 37 | * Utilizes the LZ4 subalgorithm LZ4HC with the highest possible compression level. | 37 | * Utilizes the LZ4 subalgorithm LZ4HC with the highest possible compression level. |
| @@ -40,7 +40,7 @@ std::vector<u8> CompressDataLZ4HC(std::span<const u8> source, s32 compression_le | |||
| 40 | * | 40 | * |
| 41 | * @return the compressed data. | 41 | * @return the compressed data. |
| 42 | */ | 42 | */ |
| 43 | std::vector<u8> CompressDataLZ4HCMax(std::span<const u8> source); | 43 | [[nodiscard]] std::vector<u8> CompressDataLZ4HCMax(std::span<const u8> source); |
| 44 | 44 | ||
| 45 | /** | 45 | /** |
| 46 | * Decompresses a source memory region with LZ4 and returns the uncompressed data in a vector. | 46 | * Decompresses a source memory region with LZ4 and returns the uncompressed data in a vector. |
| @@ -50,6 +50,7 @@ std::vector<u8> CompressDataLZ4HCMax(std::span<const u8> source); | |||
| 50 | * | 50 | * |
| 51 | * @return the decompressed data. | 51 | * @return the decompressed data. |
| 52 | */ | 52 | */ |
| 53 | std::vector<u8> DecompressDataLZ4(const std::vector<u8>& compressed, std::size_t uncompressed_size); | 53 | [[nodiscard]] std::vector<u8> DecompressDataLZ4(const std::vector<u8>& compressed, |
| 54 | std::size_t uncompressed_size); | ||
| 54 | 55 | ||
| 55 | } // namespace Common::Compression \ No newline at end of file | 56 | } // namespace Common::Compression \ No newline at end of file |
diff --git a/src/common/math_util.h b/src/common/math_util.h index abca3177c..cc35c90ee 100644 --- a/src/common/math_util.h +++ b/src/common/math_util.h | |||
| @@ -23,7 +23,7 @@ struct Rectangle { | |||
| 23 | constexpr Rectangle(T left, T top, T right, T bottom) | 23 | constexpr Rectangle(T left, T top, T right, T bottom) |
| 24 | : left(left), top(top), right(right), bottom(bottom) {} | 24 | : left(left), top(top), right(right), bottom(bottom) {} |
| 25 | 25 | ||
| 26 | T GetWidth() const { | 26 | [[nodiscard]] T GetWidth() const { |
| 27 | if constexpr (std::is_floating_point_v<T>) { | 27 | if constexpr (std::is_floating_point_v<T>) { |
| 28 | return std::abs(right - left); | 28 | return std::abs(right - left); |
| 29 | } else { | 29 | } else { |
| @@ -31,7 +31,7 @@ struct Rectangle { | |||
| 31 | } | 31 | } |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | T GetHeight() const { | 34 | [[nodiscard]] T GetHeight() const { |
| 35 | if constexpr (std::is_floating_point_v<T>) { | 35 | if constexpr (std::is_floating_point_v<T>) { |
| 36 | return std::abs(bottom - top); | 36 | return std::abs(bottom - top); |
| 37 | } else { | 37 | } else { |
| @@ -39,15 +39,15 @@ struct Rectangle { | |||
| 39 | } | 39 | } |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | Rectangle<T> TranslateX(const T x) const { | 42 | [[nodiscard]] Rectangle<T> TranslateX(const T x) const { |
| 43 | return Rectangle{left + x, top, right + x, bottom}; | 43 | return Rectangle{left + x, top, right + x, bottom}; |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | Rectangle<T> TranslateY(const T y) const { | 46 | [[nodiscard]] Rectangle<T> TranslateY(const T y) const { |
| 47 | return Rectangle{left, top + y, right, bottom + y}; | 47 | return Rectangle{left, top + y, right, bottom + y}; |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | Rectangle<T> Scale(const float s) const { | 50 | [[nodiscard]] Rectangle<T> Scale(const float s) const { |
| 51 | return Rectangle{left, top, static_cast<T>(left + GetWidth() * s), | 51 | return Rectangle{left, top, static_cast<T>(left + GetWidth() * s), |
| 52 | static_cast<T>(top + GetHeight() * s)}; | 52 | static_cast<T>(top + GetHeight() * s)}; |
| 53 | } | 53 | } |
diff --git a/src/common/memory_detect.h b/src/common/memory_detect.h index a73c0f3f4..0f73751c8 100644 --- a/src/common/memory_detect.h +++ b/src/common/memory_detect.h | |||
| @@ -17,6 +17,6 @@ struct MemoryInfo { | |||
| 17 | * Gets the memory info of the host system | 17 | * Gets the memory info of the host system |
| 18 | * @return Reference to a MemoryInfo struct with the physical and swap memory sizes in bytes | 18 | * @return Reference to a MemoryInfo struct with the physical and swap memory sizes in bytes |
| 19 | */ | 19 | */ |
| 20 | const MemoryInfo& GetMemInfo(); | 20 | [[nodiscard]] const MemoryInfo& GetMemInfo(); |
| 21 | 21 | ||
| 22 | } // namespace Common \ No newline at end of file | 22 | } // namespace Common \ No newline at end of file |
diff --git a/src/common/multi_level_queue.h b/src/common/multi_level_queue.h index 50acfdbf2..4b305bf40 100644 --- a/src/common/multi_level_queue.h +++ b/src/common/multi_level_queue.h | |||
| @@ -223,15 +223,15 @@ public: | |||
| 223 | ListShiftForward(levels[priority], n); | 223 | ListShiftForward(levels[priority], n); |
| 224 | } | 224 | } |
| 225 | 225 | ||
| 226 | std::size_t depth() const { | 226 | [[nodiscard]] std::size_t depth() const { |
| 227 | return Depth; | 227 | return Depth; |
| 228 | } | 228 | } |
| 229 | 229 | ||
| 230 | std::size_t size(u32 priority) const { | 230 | [[nodiscard]] std::size_t size(u32 priority) const { |
| 231 | return levels[priority].size(); | 231 | return levels[priority].size(); |
| 232 | } | 232 | } |
| 233 | 233 | ||
| 234 | std::size_t size() const { | 234 | [[nodiscard]] std::size_t size() const { |
| 235 | u64 priorities = used_priorities; | 235 | u64 priorities = used_priorities; |
| 236 | std::size_t size = 0; | 236 | std::size_t size = 0; |
| 237 | while (priorities != 0) { | 237 | while (priorities != 0) { |
| @@ -242,64 +242,64 @@ public: | |||
| 242 | return size; | 242 | return size; |
| 243 | } | 243 | } |
| 244 | 244 | ||
| 245 | bool empty() const { | 245 | [[nodiscard]] bool empty() const { |
| 246 | return used_priorities == 0; | 246 | return used_priorities == 0; |
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | bool empty(u32 priority) const { | 249 | [[nodiscard]] bool empty(u32 priority) const { |
| 250 | return (used_priorities & (1ULL << priority)) == 0; | 250 | return (used_priorities & (1ULL << priority)) == 0; |
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | u32 highest_priority_set(u32 max_priority = 0) const { | 253 | [[nodiscard]] u32 highest_priority_set(u32 max_priority = 0) const { |
| 254 | const u64 priorities = | 254 | const u64 priorities = |
| 255 | max_priority == 0 ? used_priorities : (used_priorities & ~((1ULL << max_priority) - 1)); | 255 | max_priority == 0 ? used_priorities : (used_priorities & ~((1ULL << max_priority) - 1)); |
| 256 | return priorities == 0 ? Depth : static_cast<u32>(CountTrailingZeroes64(priorities)); | 256 | return priorities == 0 ? Depth : static_cast<u32>(CountTrailingZeroes64(priorities)); |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | u32 lowest_priority_set(u32 min_priority = Depth - 1) const { | 259 | [[nodiscard]] u32 lowest_priority_set(u32 min_priority = Depth - 1) const { |
| 260 | const u64 priorities = min_priority >= Depth - 1 | 260 | const u64 priorities = min_priority >= Depth - 1 |
| 261 | ? used_priorities | 261 | ? used_priorities |
| 262 | : (used_priorities & ((1ULL << (min_priority + 1)) - 1)); | 262 | : (used_priorities & ((1ULL << (min_priority + 1)) - 1)); |
| 263 | return priorities == 0 ? Depth : 63 - CountLeadingZeroes64(priorities); | 263 | return priorities == 0 ? Depth : 63 - CountLeadingZeroes64(priorities); |
| 264 | } | 264 | } |
| 265 | 265 | ||
| 266 | const_iterator cbegin(u32 max_prio = 0) const { | 266 | [[nodiscard]] const_iterator cbegin(u32 max_prio = 0) const { |
| 267 | const u32 priority = highest_priority_set(max_prio); | 267 | const u32 priority = highest_priority_set(max_prio); |
| 268 | return priority == Depth ? cend() | 268 | return priority == Depth ? cend() |
| 269 | : const_iterator{*this, levels[priority].cbegin(), priority}; | 269 | : const_iterator{*this, levels[priority].cbegin(), priority}; |
| 270 | } | 270 | } |
| 271 | const_iterator begin(u32 max_prio = 0) const { | 271 | [[nodiscard]] const_iterator begin(u32 max_prio = 0) const { |
| 272 | return cbegin(max_prio); | 272 | return cbegin(max_prio); |
| 273 | } | 273 | } |
| 274 | iterator begin(u32 max_prio = 0) { | 274 | [[nodiscard]] iterator begin(u32 max_prio = 0) { |
| 275 | const u32 priority = highest_priority_set(max_prio); | 275 | const u32 priority = highest_priority_set(max_prio); |
| 276 | return priority == Depth ? end() : iterator{*this, levels[priority].begin(), priority}; | 276 | return priority == Depth ? end() : iterator{*this, levels[priority].begin(), priority}; |
| 277 | } | 277 | } |
| 278 | 278 | ||
| 279 | const_iterator cend(u32 min_prio = Depth - 1) const { | 279 | [[nodiscard]] const_iterator cend(u32 min_prio = Depth - 1) const { |
| 280 | return min_prio == Depth - 1 ? const_iterator{*this, Depth} : cbegin(min_prio + 1); | 280 | return min_prio == Depth - 1 ? const_iterator{*this, Depth} : cbegin(min_prio + 1); |
| 281 | } | 281 | } |
| 282 | const_iterator end(u32 min_prio = Depth - 1) const { | 282 | [[nodiscard]] const_iterator end(u32 min_prio = Depth - 1) const { |
| 283 | return cend(min_prio); | 283 | return cend(min_prio); |
| 284 | } | 284 | } |
| 285 | iterator end(u32 min_prio = Depth - 1) { | 285 | [[nodiscard]] iterator end(u32 min_prio = Depth - 1) { |
| 286 | return min_prio == Depth - 1 ? iterator{*this, Depth} : begin(min_prio + 1); | 286 | return min_prio == Depth - 1 ? iterator{*this, Depth} : begin(min_prio + 1); |
| 287 | } | 287 | } |
| 288 | 288 | ||
| 289 | T& front(u32 max_priority = 0) { | 289 | [[nodiscard]] T& front(u32 max_priority = 0) { |
| 290 | const u32 priority = highest_priority_set(max_priority); | 290 | const u32 priority = highest_priority_set(max_priority); |
| 291 | return levels[priority == Depth ? 0 : priority].front(); | 291 | return levels[priority == Depth ? 0 : priority].front(); |
| 292 | } | 292 | } |
| 293 | const T& front(u32 max_priority = 0) const { | 293 | [[nodiscard]] const T& front(u32 max_priority = 0) const { |
| 294 | const u32 priority = highest_priority_set(max_priority); | 294 | const u32 priority = highest_priority_set(max_priority); |
| 295 | return levels[priority == Depth ? 0 : priority].front(); | 295 | return levels[priority == Depth ? 0 : priority].front(); |
| 296 | } | 296 | } |
| 297 | 297 | ||
| 298 | T back(u32 min_priority = Depth - 1) { | 298 | [[nodiscard]] T& back(u32 min_priority = Depth - 1) { |
| 299 | const u32 priority = lowest_priority_set(min_priority); // intended | 299 | const u32 priority = lowest_priority_set(min_priority); // intended |
| 300 | return levels[priority == Depth ? 63 : priority].back(); | 300 | return levels[priority == Depth ? 63 : priority].back(); |
| 301 | } | 301 | } |
| 302 | const T& back(u32 min_priority = Depth - 1) const { | 302 | [[nodiscard]] const T& back(u32 min_priority = Depth - 1) const { |
| 303 | const u32 priority = lowest_priority_set(min_priority); // intended | 303 | const u32 priority = lowest_priority_set(min_priority); // intended |
| 304 | return levels[priority == Depth ? 63 : priority].back(); | 304 | return levels[priority == Depth ? 63 : priority].back(); |
| 305 | } | 305 | } |
| @@ -329,7 +329,8 @@ private: | |||
| 329 | in_list.splice(position, out_list, element); | 329 | in_list.splice(position, out_list, element); |
| 330 | } | 330 | } |
| 331 | 331 | ||
| 332 | static const_list_iterator ListIterateTo(const std::list<T>& list, const T& element) { | 332 | [[nodiscard]] static const_list_iterator ListIterateTo(const std::list<T>& list, |
| 333 | const T& element) { | ||
| 333 | auto it = list.cbegin(); | 334 | auto it = list.cbegin(); |
| 334 | while (it != list.cend() && *it != element) { | 335 | while (it != list.cend() && *it != element) { |
| 335 | ++it; | 336 | ++it; |
diff --git a/src/common/page_table.h b/src/common/page_table.h index 1e8bd3187..cf5eed780 100644 --- a/src/common/page_table.h +++ b/src/common/page_table.h | |||
| @@ -36,11 +36,11 @@ struct SpecialRegion { | |||
| 36 | 36 | ||
| 37 | MemoryHookPointer handler; | 37 | MemoryHookPointer handler; |
| 38 | 38 | ||
| 39 | bool operator<(const SpecialRegion& other) const { | 39 | [[nodiscard]] bool operator<(const SpecialRegion& other) const { |
| 40 | return std::tie(type, handler) < std::tie(other.type, other.handler); | 40 | return std::tie(type, handler) < std::tie(other.type, other.handler); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | bool operator==(const SpecialRegion& other) const { | 43 | [[nodiscard]] bool operator==(const SpecialRegion& other) const { |
| 44 | return std::tie(type, handler) == std::tie(other.type, other.handler); | 44 | return std::tie(type, handler) == std::tie(other.type, other.handler); |
| 45 | } | 45 | } |
| 46 | }; | 46 | }; |
diff --git a/src/common/param_package.h b/src/common/param_package.h index 6a0a9b656..c8a70bfa9 100644 --- a/src/common/param_package.h +++ b/src/common/param_package.h | |||
| @@ -24,14 +24,14 @@ public: | |||
| 24 | ParamPackage& operator=(const ParamPackage& other) = default; | 24 | ParamPackage& operator=(const ParamPackage& other) = default; |
| 25 | ParamPackage& operator=(ParamPackage&& other) = default; | 25 | ParamPackage& operator=(ParamPackage&& other) = default; |
| 26 | 26 | ||
| 27 | std::string Serialize() const; | 27 | [[nodiscard]] std::string Serialize() const; |
| 28 | std::string Get(const std::string& key, const std::string& default_value) const; | 28 | [[nodiscard]] std::string Get(const std::string& key, const std::string& default_value) const; |
| 29 | int Get(const std::string& key, int default_value) const; | 29 | [[nodiscard]] int Get(const std::string& key, int default_value) const; |
| 30 | float Get(const std::string& key, float default_value) const; | 30 | [[nodiscard]] float Get(const std::string& key, float default_value) const; |
| 31 | void Set(const std::string& key, std::string value); | 31 | void Set(const std::string& key, std::string value); |
| 32 | void Set(const std::string& key, int value); | 32 | void Set(const std::string& key, int value); |
| 33 | void Set(const std::string& key, float value); | 33 | void Set(const std::string& key, float value); |
| 34 | bool Has(const std::string& key) const; | 34 | [[nodiscard]] bool Has(const std::string& key) const; |
| 35 | void Erase(const std::string& key); | 35 | void Erase(const std::string& key); |
| 36 | void Clear(); | 36 | void Clear(); |
| 37 | 37 | ||
diff --git a/src/common/quaternion.h b/src/common/quaternion.h index 370198ae0..da44f35cd 100644 --- a/src/common/quaternion.h +++ b/src/common/quaternion.h | |||
| @@ -14,35 +14,36 @@ public: | |||
| 14 | Vec3<T> xyz; | 14 | Vec3<T> xyz; |
| 15 | T w{}; | 15 | T w{}; |
| 16 | 16 | ||
| 17 | Quaternion<decltype(-T{})> Inverse() const { | 17 | [[nodiscard]] Quaternion<decltype(-T{})> Inverse() const { |
| 18 | return {-xyz, w}; | 18 | return {-xyz, w}; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | Quaternion<decltype(T{} + T{})> operator+(const Quaternion& other) const { | 21 | [[nodiscard]] Quaternion<decltype(T{} + T{})> operator+(const Quaternion& other) const { |
| 22 | return {xyz + other.xyz, w + other.w}; | 22 | return {xyz + other.xyz, w + other.w}; |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | Quaternion<decltype(T{} - T{})> operator-(const Quaternion& other) const { | 25 | [[nodiscard]] Quaternion<decltype(T{} - T{})> operator-(const Quaternion& other) const { |
| 26 | return {xyz - other.xyz, w - other.w}; | 26 | return {xyz - other.xyz, w - other.w}; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | Quaternion<decltype(T{} * T{} - T{} * T{})> operator*(const Quaternion& other) const { | 29 | [[nodiscard]] Quaternion<decltype(T{} * T{} - T{} * T{})> operator*( |
| 30 | const Quaternion& other) const { | ||
| 30 | return {xyz * other.w + other.xyz * w + Cross(xyz, other.xyz), | 31 | return {xyz * other.w + other.xyz * w + Cross(xyz, other.xyz), |
| 31 | w * other.w - Dot(xyz, other.xyz)}; | 32 | w * other.w - Dot(xyz, other.xyz)}; |
| 32 | } | 33 | } |
| 33 | 34 | ||
| 34 | Quaternion<T> Normalized() const { | 35 | [[nodiscard]] Quaternion<T> Normalized() const { |
| 35 | T length = std::sqrt(xyz.Length2() + w * w); | 36 | T length = std::sqrt(xyz.Length2() + w * w); |
| 36 | return {xyz / length, w / length}; | 37 | return {xyz / length, w / length}; |
| 37 | } | 38 | } |
| 38 | }; | 39 | }; |
| 39 | 40 | ||
| 40 | template <typename T> | 41 | template <typename T> |
| 41 | auto QuaternionRotate(const Quaternion<T>& q, const Vec3<T>& v) { | 42 | [[nodiscard]] auto QuaternionRotate(const Quaternion<T>& q, const Vec3<T>& v) { |
| 42 | return v + 2 * Cross(q.xyz, Cross(q.xyz, v) + v * q.w); | 43 | return v + 2 * Cross(q.xyz, Cross(q.xyz, v) + v * q.w); |
| 43 | } | 44 | } |
| 44 | 45 | ||
| 45 | inline Quaternion<float> MakeQuaternion(const Vec3<float>& axis, float angle) { | 46 | [[nodiscard]] inline Quaternion<float> MakeQuaternion(const Vec3<float>& axis, float angle) { |
| 46 | return {axis * std::sin(angle / 2), std::cos(angle / 2)}; | 47 | return {axis * std::sin(angle / 2), std::cos(angle / 2)}; |
| 47 | } | 48 | } |
| 48 | 49 | ||
diff --git a/src/common/ring_buffer.h b/src/common/ring_buffer.h index abe3b4dc2..138fa0131 100644 --- a/src/common/ring_buffer.h +++ b/src/common/ring_buffer.h | |||
| @@ -91,12 +91,12 @@ public: | |||
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | /// @returns Number of slots used | 93 | /// @returns Number of slots used |
| 94 | std::size_t Size() const { | 94 | [[nodiscard]] std::size_t Size() const { |
| 95 | return m_write_index.load() - m_read_index.load(); | 95 | return m_write_index.load() - m_read_index.load(); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | /// @returns Maximum size of ring buffer | 98 | /// @returns Maximum size of ring buffer |
| 99 | constexpr std::size_t Capacity() const { | 99 | [[nodiscard]] constexpr std::size_t Capacity() const { |
| 100 | return capacity; | 100 | return capacity; |
| 101 | } | 101 | } |
| 102 | 102 | ||
diff --git a/src/common/spin_lock.h b/src/common/spin_lock.h index 1df5528c4..4f946a258 100644 --- a/src/common/spin_lock.h +++ b/src/common/spin_lock.h | |||
| @@ -17,7 +17,7 @@ class SpinLock { | |||
| 17 | public: | 17 | public: |
| 18 | void lock(); | 18 | void lock(); |
| 19 | void unlock(); | 19 | void unlock(); |
| 20 | bool try_lock(); | 20 | [[nodiscard]] bool try_lock(); |
| 21 | 21 | ||
| 22 | private: | 22 | private: |
| 23 | std::atomic_flag lck = ATOMIC_FLAG_INIT; | 23 | std::atomic_flag lck = ATOMIC_FLAG_INIT; |
diff --git a/src/common/string_util.h b/src/common/string_util.h index 023dff5dc..a32c07c06 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h | |||
| @@ -12,19 +12,19 @@ | |||
| 12 | namespace Common { | 12 | namespace Common { |
| 13 | 13 | ||
| 14 | /// Make a string lowercase | 14 | /// Make a string lowercase |
| 15 | std::string ToLower(std::string str); | 15 | [[nodiscard]] std::string ToLower(std::string str); |
| 16 | 16 | ||
| 17 | /// Make a string uppercase | 17 | /// Make a string uppercase |
| 18 | std::string ToUpper(std::string str); | 18 | [[nodiscard]] std::string ToUpper(std::string str); |
| 19 | 19 | ||
| 20 | std::string StringFromBuffer(const std::vector<u8>& data); | 20 | [[nodiscard]] std::string StringFromBuffer(const std::vector<u8>& data); |
| 21 | 21 | ||
| 22 | std::string StripSpaces(const std::string& s); | 22 | [[nodiscard]] std::string StripSpaces(const std::string& s); |
| 23 | std::string StripQuotes(const std::string& s); | 23 | [[nodiscard]] std::string StripQuotes(const std::string& s); |
| 24 | 24 | ||
| 25 | std::string StringFromBool(bool value); | 25 | [[nodiscard]] std::string StringFromBool(bool value); |
| 26 | 26 | ||
| 27 | std::string TabsToSpaces(int tab_size, std::string in); | 27 | [[nodiscard]] std::string TabsToSpaces(int tab_size, std::string in); |
| 28 | 28 | ||
| 29 | void SplitString(const std::string& str, char delim, std::vector<std::string>& output); | 29 | void SplitString(const std::string& str, char delim, std::vector<std::string>& output); |
| 30 | 30 | ||
| @@ -34,14 +34,15 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _ | |||
| 34 | 34 | ||
| 35 | void BuildCompleteFilename(std::string& _CompleteFilename, const std::string& _Path, | 35 | void BuildCompleteFilename(std::string& _CompleteFilename, const std::string& _Path, |
| 36 | const std::string& _Filename); | 36 | const std::string& _Filename); |
| 37 | std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest); | 37 | [[nodiscard]] std::string ReplaceAll(std::string result, const std::string& src, |
| 38 | const std::string& dest); | ||
| 38 | 39 | ||
| 39 | std::string UTF16ToUTF8(const std::u16string& input); | 40 | [[nodiscard]] std::string UTF16ToUTF8(const std::u16string& input); |
| 40 | std::u16string UTF8ToUTF16(const std::string& input); | 41 | [[nodiscard]] std::u16string UTF8ToUTF16(const std::string& input); |
| 41 | 42 | ||
| 42 | #ifdef _WIN32 | 43 | #ifdef _WIN32 |
| 43 | std::string UTF16ToUTF8(const std::wstring& input); | 44 | [[nodiscard]] std::string UTF16ToUTF8(const std::wstring& input); |
| 44 | std::wstring UTF8ToUTF16W(const std::string& str); | 45 | [[nodiscard]] std::wstring UTF8ToUTF16W(const std::string& str); |
| 45 | 46 | ||
| 46 | #endif | 47 | #endif |
| 47 | 48 | ||
| @@ -50,7 +51,7 @@ std::wstring UTF8ToUTF16W(const std::string& str); | |||
| 50 | * `other` for equality. | 51 | * `other` for equality. |
| 51 | */ | 52 | */ |
| 52 | template <typename InIt> | 53 | template <typename InIt> |
| 53 | bool ComparePartialString(InIt begin, InIt end, const char* other) { | 54 | [[nodiscard]] bool ComparePartialString(InIt begin, InIt end, const char* other) { |
| 54 | for (; begin != end && *other != '\0'; ++begin, ++other) { | 55 | for (; begin != end && *other != '\0'; ++begin, ++other) { |
| 55 | if (*begin != *other) { | 56 | if (*begin != *other) { |
| 56 | return false; | 57 | return false; |
| @@ -64,14 +65,15 @@ bool ComparePartialString(InIt begin, InIt end, const char* other) { | |||
| 64 | * Creates a std::string from a fixed-size NUL-terminated char buffer. If the buffer isn't | 65 | * Creates a std::string from a fixed-size NUL-terminated char buffer. If the buffer isn't |
| 65 | * NUL-terminated then the string ends at max_len characters. | 66 | * NUL-terminated then the string ends at max_len characters. |
| 66 | */ | 67 | */ |
| 67 | std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t max_len); | 68 | [[nodiscard]] std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, |
| 69 | std::size_t max_len); | ||
| 68 | 70 | ||
| 69 | /** | 71 | /** |
| 70 | * Creates a UTF-16 std::u16string from a fixed-size NUL-terminated char buffer. If the buffer isn't | 72 | * Creates a UTF-16 std::u16string from a fixed-size NUL-terminated char buffer. If the buffer isn't |
| 71 | * null-terminated, then the string ends at the greatest multiple of two less then or equal to | 73 | * null-terminated, then the string ends at the greatest multiple of two less then or equal to |
| 72 | * max_len_bytes. | 74 | * max_len_bytes. |
| 73 | */ | 75 | */ |
| 74 | std::u16string UTF16StringFromFixedZeroTerminatedBuffer(std::u16string_view buffer, | 76 | [[nodiscard]] std::u16string UTF16StringFromFixedZeroTerminatedBuffer(std::u16string_view buffer, |
| 75 | std::size_t max_len); | 77 | std::size_t max_len); |
| 76 | 78 | ||
| 77 | } // namespace Common | 79 | } // namespace Common |
diff --git a/src/common/telemetry.h b/src/common/telemetry.h index 854a73fae..4aa299f9a 100644 --- a/src/common/telemetry.h +++ b/src/common/telemetry.h | |||
| @@ -63,30 +63,30 @@ public: | |||
| 63 | 63 | ||
| 64 | void Accept(VisitorInterface& visitor) const override; | 64 | void Accept(VisitorInterface& visitor) const override; |
| 65 | 65 | ||
| 66 | const std::string& GetName() const override { | 66 | [[nodiscard]] const std::string& GetName() const override { |
| 67 | return name; | 67 | return name; |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | /** | 70 | /** |
| 71 | * Returns the type of the field. | 71 | * Returns the type of the field. |
| 72 | */ | 72 | */ |
| 73 | FieldType GetType() const { | 73 | [[nodiscard]] FieldType GetType() const { |
| 74 | return type; | 74 | return type; |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | /** | 77 | /** |
| 78 | * Returns the value of the field. | 78 | * Returns the value of the field. |
| 79 | */ | 79 | */ |
| 80 | const T& GetValue() const { | 80 | [[nodiscard]] const T& GetValue() const { |
| 81 | return value; | 81 | return value; |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | bool operator==(const Field& other) const { | 84 | [[nodiscard]] bool operator==(const Field& other) const { |
| 85 | return (type == other.type) && (name == other.name) && (value == other.value); | 85 | return (type == other.type) && (name == other.name) && (value == other.value); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | bool operator!=(const Field& other) const { | 88 | [[nodiscard]] bool operator!=(const Field& other) const { |
| 89 | return !(*this == other); | 89 | return !operator==(other); |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | private: | 92 | private: |
diff --git a/src/common/thread_queue_list.h b/src/common/thread_queue_list.h index 791f99a8c..def9e5d8d 100644 --- a/src/common/thread_queue_list.h +++ b/src/common/thread_queue_list.h | |||
| @@ -18,14 +18,14 @@ struct ThreadQueueList { | |||
| 18 | using Priority = unsigned int; | 18 | using Priority = unsigned int; |
| 19 | 19 | ||
| 20 | // Number of priority levels. (Valid levels are [0..NUM_QUEUES).) | 20 | // Number of priority levels. (Valid levels are [0..NUM_QUEUES).) |
| 21 | static const Priority NUM_QUEUES = N; | 21 | static constexpr Priority NUM_QUEUES = N; |
| 22 | 22 | ||
| 23 | ThreadQueueList() { | 23 | ThreadQueueList() { |
| 24 | first = nullptr; | 24 | first = nullptr; |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | // Only for debugging, returns priority level. | 27 | // Only for debugging, returns priority level. |
| 28 | Priority contains(const T& uid) const { | 28 | [[nodiscard]] Priority contains(const T& uid) const { |
| 29 | for (Priority i = 0; i < NUM_QUEUES; ++i) { | 29 | for (Priority i = 0; i < NUM_QUEUES; ++i) { |
| 30 | const Queue& cur = queues[i]; | 30 | const Queue& cur = queues[i]; |
| 31 | if (std::find(cur.data.cbegin(), cur.data.cend(), uid) != cur.data.cend()) { | 31 | if (std::find(cur.data.cbegin(), cur.data.cend(), uid) != cur.data.cend()) { |
| @@ -36,7 +36,7 @@ struct ThreadQueueList { | |||
| 36 | return -1; | 36 | return -1; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | T get_first() const { | 39 | [[nodiscard]] T get_first() const { |
| 40 | const Queue* cur = first; | 40 | const Queue* cur = first; |
| 41 | while (cur != nullptr) { | 41 | while (cur != nullptr) { |
| 42 | if (!cur->data.empty()) { | 42 | if (!cur->data.empty()) { |
| @@ -49,7 +49,7 @@ struct ThreadQueueList { | |||
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | template <typename UnaryPredicate> | 51 | template <typename UnaryPredicate> |
| 52 | T get_first_filter(UnaryPredicate filter) const { | 52 | [[nodiscard]] T get_first_filter(UnaryPredicate filter) const { |
| 53 | const Queue* cur = first; | 53 | const Queue* cur = first; |
| 54 | while (cur != nullptr) { | 54 | while (cur != nullptr) { |
| 55 | if (!cur->data.empty()) { | 55 | if (!cur->data.empty()) { |
| @@ -129,7 +129,7 @@ struct ThreadQueueList { | |||
| 129 | first = nullptr; | 129 | first = nullptr; |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | bool empty(Priority priority) const { | 132 | [[nodiscard]] bool empty(Priority priority) const { |
| 133 | const Queue* cur = &queues[priority]; | 133 | const Queue* cur = &queues[priority]; |
| 134 | return cur->data.empty(); | 134 | return cur->data.empty(); |
| 135 | } | 135 | } |
diff --git a/src/common/threadsafe_queue.h b/src/common/threadsafe_queue.h index 8268bbd5c..a4647314a 100644 --- a/src/common/threadsafe_queue.h +++ b/src/common/threadsafe_queue.h | |||
| @@ -25,15 +25,15 @@ public: | |||
| 25 | delete read_ptr; | 25 | delete read_ptr; |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | std::size_t Size() const { | 28 | [[nodiscard]] std::size_t Size() const { |
| 29 | return size.load(); | 29 | return size.load(); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | bool Empty() const { | 32 | [[nodiscard]] bool Empty() const { |
| 33 | return Size() == 0; | 33 | return Size() == 0; |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | T& Front() const { | 36 | [[nodiscard]] T& Front() const { |
| 37 | return read_ptr->current; | 37 | return read_ptr->current; |
| 38 | } | 38 | } |
| 39 | 39 | ||
| @@ -130,15 +130,15 @@ private: | |||
| 130 | template <typename T> | 130 | template <typename T> |
| 131 | class MPSCQueue { | 131 | class MPSCQueue { |
| 132 | public: | 132 | public: |
| 133 | std::size_t Size() const { | 133 | [[nodiscard]] std::size_t Size() const { |
| 134 | return spsc_queue.Size(); | 134 | return spsc_queue.Size(); |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | bool Empty() const { | 137 | [[nodiscard]] bool Empty() const { |
| 138 | return spsc_queue.Empty(); | 138 | return spsc_queue.Empty(); |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | T& Front() const { | 141 | [[nodiscard]] T& Front() const { |
| 142 | return spsc_queue.Front(); | 142 | return spsc_queue.Front(); |
| 143 | } | 143 | } |
| 144 | 144 | ||
diff --git a/src/common/time_zone.h b/src/common/time_zone.h index 945daa09c..9f5939ca5 100644 --- a/src/common/time_zone.h +++ b/src/common/time_zone.h | |||
| @@ -10,9 +10,9 @@ | |||
| 10 | namespace Common::TimeZone { | 10 | namespace Common::TimeZone { |
| 11 | 11 | ||
| 12 | /// Gets the default timezone, i.e. "GMT" | 12 | /// Gets the default timezone, i.e. "GMT" |
| 13 | std::string GetDefaultTimeZone(); | 13 | [[nodiscard]] std::string GetDefaultTimeZone(); |
| 14 | 14 | ||
| 15 | /// Gets the offset of the current timezone (from the default), in seconds | 15 | /// Gets the offset of the current timezone (from the default), in seconds |
| 16 | std::chrono::seconds GetCurrentOffsetSeconds(); | 16 | [[nodiscard]] std::chrono::seconds GetCurrentOffsetSeconds(); |
| 17 | 17 | ||
| 18 | } // namespace Common::TimeZone | 18 | } // namespace Common::TimeZone |
diff --git a/src/common/timer.h b/src/common/timer.h index 27b521baa..8894a143d 100644 --- a/src/common/timer.h +++ b/src/common/timer.h | |||
| @@ -19,18 +19,18 @@ public: | |||
| 19 | 19 | ||
| 20 | // The time difference is always returned in milliseconds, regardless of alternative internal | 20 | // The time difference is always returned in milliseconds, regardless of alternative internal |
| 21 | // representation | 21 | // representation |
| 22 | std::chrono::milliseconds GetTimeDifference(); | 22 | [[nodiscard]] std::chrono::milliseconds GetTimeDifference(); |
| 23 | void AddTimeDifference(); | 23 | void AddTimeDifference(); |
| 24 | 24 | ||
| 25 | static std::chrono::seconds GetTimeSinceJan1970(); | 25 | [[nodiscard]] static std::chrono::seconds GetTimeSinceJan1970(); |
| 26 | static std::chrono::seconds GetLocalTimeSinceJan1970(); | 26 | [[nodiscard]] static std::chrono::seconds GetLocalTimeSinceJan1970(); |
| 27 | static double GetDoubleTime(); | 27 | [[nodiscard]] static double GetDoubleTime(); |
| 28 | 28 | ||
| 29 | static std::string GetTimeFormatted(); | 29 | [[nodiscard]] static std::string GetTimeFormatted(); |
| 30 | std::string GetTimeElapsedFormatted() const; | 30 | [[nodiscard]] std::string GetTimeElapsedFormatted() const; |
| 31 | std::chrono::milliseconds GetTimeElapsed(); | 31 | [[nodiscard]] std::chrono::milliseconds GetTimeElapsed(); |
| 32 | 32 | ||
| 33 | static std::chrono::milliseconds GetTimeMs(); | 33 | [[nodiscard]] static std::chrono::milliseconds GetTimeMs(); |
| 34 | 34 | ||
| 35 | private: | 35 | private: |
| 36 | std::chrono::milliseconds m_LastTime; | 36 | std::chrono::milliseconds m_LastTime; |
diff --git a/src/common/uint128.h b/src/common/uint128.h index 503cd2d0c..969259ab6 100644 --- a/src/common/uint128.h +++ b/src/common/uint128.h | |||
| @@ -10,13 +10,13 @@ | |||
| 10 | namespace Common { | 10 | namespace Common { |
| 11 | 11 | ||
| 12 | // This function multiplies 2 u64 values and divides it by a u64 value. | 12 | // This function multiplies 2 u64 values and divides it by a u64 value. |
| 13 | u64 MultiplyAndDivide64(u64 a, u64 b, u64 d); | 13 | [[nodiscard]] u64 MultiplyAndDivide64(u64 a, u64 b, u64 d); |
| 14 | 14 | ||
| 15 | // This function multiplies 2 u64 values and produces a u128 value; | 15 | // This function multiplies 2 u64 values and produces a u128 value; |
| 16 | u128 Multiply64Into128(u64 a, u64 b); | 16 | [[nodiscard]] u128 Multiply64Into128(u64 a, u64 b); |
| 17 | 17 | ||
| 18 | // This function divides a u128 by a u32 value and produces two u64 values: | 18 | // This function divides a u128 by a u32 value and produces two u64 values: |
| 19 | // the result of division and the remainder | 19 | // the result of division and the remainder |
| 20 | std::pair<u64, u64> Divide128On32(u128 dividend, u32 divisor); | 20 | [[nodiscard]] std::pair<u64, u64> Divide128On32(u128 dividend, u32 divisor); |
| 21 | 21 | ||
| 22 | } // namespace Common | 22 | } // namespace Common |
diff --git a/src/common/uuid.h b/src/common/uuid.h index 4d3af8cec..4ab9a25f0 100644 --- a/src/common/uuid.h +++ b/src/common/uuid.h | |||
| @@ -19,21 +19,21 @@ struct UUID { | |||
| 19 | constexpr explicit UUID(const u128& id) : uuid{id} {} | 19 | constexpr explicit UUID(const u128& id) : uuid{id} {} |
| 20 | constexpr explicit UUID(const u64 lo, const u64 hi) : uuid{{lo, hi}} {} | 20 | constexpr explicit UUID(const u64 lo, const u64 hi) : uuid{{lo, hi}} {} |
| 21 | 21 | ||
| 22 | constexpr explicit operator bool() const { | 22 | [[nodiscard]] constexpr explicit operator bool() const { |
| 23 | return uuid[0] != INVALID_UUID[0] && uuid[1] != INVALID_UUID[1]; | 23 | return uuid[0] != INVALID_UUID[0] && uuid[1] != INVALID_UUID[1]; |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | constexpr bool operator==(const UUID& rhs) const { | 26 | [[nodiscard]] constexpr bool operator==(const UUID& rhs) const { |
| 27 | // TODO(DarkLordZach): Replace with uuid == rhs.uuid with C++20 | 27 | // TODO(DarkLordZach): Replace with uuid == rhs.uuid with C++20 |
| 28 | return uuid[0] == rhs.uuid[0] && uuid[1] == rhs.uuid[1]; | 28 | return uuid[0] == rhs.uuid[0] && uuid[1] == rhs.uuid[1]; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | constexpr bool operator!=(const UUID& rhs) const { | 31 | [[nodiscard]] constexpr bool operator!=(const UUID& rhs) const { |
| 32 | return !operator==(rhs); | 32 | return !operator==(rhs); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | // TODO(ogniK): Properly generate uuids based on RFC-4122 | 35 | // TODO(ogniK): Properly generate uuids based on RFC-4122 |
| 36 | static UUID Generate(); | 36 | [[nodiscard]] static UUID Generate(); |
| 37 | 37 | ||
| 38 | // Set the UUID to {0,0} to be considered an invalid user | 38 | // Set the UUID to {0,0} to be considered an invalid user |
| 39 | constexpr void Invalidate() { | 39 | constexpr void Invalidate() { |
| @@ -41,12 +41,12 @@ struct UUID { | |||
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | // TODO(ogniK): Properly generate a Nintendo ID | 43 | // TODO(ogniK): Properly generate a Nintendo ID |
| 44 | constexpr u64 GetNintendoID() const { | 44 | [[nodiscard]] constexpr u64 GetNintendoID() const { |
| 45 | return uuid[0]; | 45 | return uuid[0]; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | std::string Format() const; | 48 | [[nodiscard]] std::string Format() const; |
| 49 | std::string FormatSwitch() const; | 49 | [[nodiscard]] std::string FormatSwitch() const; |
| 50 | }; | 50 | }; |
| 51 | static_assert(sizeof(UUID) == 16, "UUID is an invalid size!"); | 51 | static_assert(sizeof(UUID) == 16, "UUID is an invalid size!"); |
| 52 | 52 | ||
diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 429485329..2a0fcf541 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h | |||
| @@ -52,15 +52,15 @@ public: | |||
| 52 | constexpr Vec2(const T& x_, const T& y_) : x(x_), y(y_) {} | 52 | constexpr Vec2(const T& x_, const T& y_) : x(x_), y(y_) {} |
| 53 | 53 | ||
| 54 | template <typename T2> | 54 | template <typename T2> |
| 55 | constexpr Vec2<T2> Cast() const { | 55 | [[nodiscard]] constexpr Vec2<T2> Cast() const { |
| 56 | return Vec2<T2>(static_cast<T2>(x), static_cast<T2>(y)); | 56 | return Vec2<T2>(static_cast<T2>(x), static_cast<T2>(y)); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | static constexpr Vec2 AssignToAll(const T& f) { | 59 | [[nodiscard]] static constexpr Vec2 AssignToAll(const T& f) { |
| 60 | return Vec2{f, f}; | 60 | return Vec2{f, f}; |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | constexpr Vec2<decltype(T{} + T{})> operator+(const Vec2& other) const { | 63 | [[nodiscard]] constexpr Vec2<decltype(T{} + T{})> operator+(const Vec2& other) const { |
| 64 | return {x + other.x, y + other.y}; | 64 | return {x + other.x, y + other.y}; |
| 65 | } | 65 | } |
| 66 | constexpr Vec2& operator+=(const Vec2& other) { | 66 | constexpr Vec2& operator+=(const Vec2& other) { |
| @@ -68,7 +68,7 @@ public: | |||
| 68 | y += other.y; | 68 | y += other.y; |
| 69 | return *this; | 69 | return *this; |
| 70 | } | 70 | } |
| 71 | constexpr Vec2<decltype(T{} - T{})> operator-(const Vec2& other) const { | 71 | [[nodiscard]] constexpr Vec2<decltype(T{} - T{})> operator-(const Vec2& other) const { |
| 72 | return {x - other.x, y - other.y}; | 72 | return {x - other.x, y - other.y}; |
| 73 | } | 73 | } |
| 74 | constexpr Vec2& operator-=(const Vec2& other) { | 74 | constexpr Vec2& operator-=(const Vec2& other) { |
| @@ -78,15 +78,15 @@ public: | |||
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | template <typename U = T> | 80 | template <typename U = T> |
| 81 | constexpr Vec2<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const { | 81 | [[nodiscard]] constexpr Vec2<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const { |
| 82 | return {-x, -y}; | 82 | return {-x, -y}; |
| 83 | } | 83 | } |
| 84 | constexpr Vec2<decltype(T{} * T{})> operator*(const Vec2& other) const { | 84 | [[nodiscard]] constexpr Vec2<decltype(T{} * T{})> operator*(const Vec2& other) const { |
| 85 | return {x * other.x, y * other.y}; | 85 | return {x * other.x, y * other.y}; |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | template <typename V> | 88 | template <typename V> |
| 89 | constexpr Vec2<decltype(T{} * V{})> operator*(const V& f) const { | 89 | [[nodiscard]] constexpr Vec2<decltype(T{} * V{})> operator*(const V& f) const { |
| 90 | return {x * f, y * f}; | 90 | return {x * f, y * f}; |
| 91 | } | 91 | } |
| 92 | 92 | ||
| @@ -97,7 +97,7 @@ public: | |||
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | template <typename V> | 99 | template <typename V> |
| 100 | constexpr Vec2<decltype(T{} / V{})> operator/(const V& f) const { | 100 | [[nodiscard]] constexpr Vec2<decltype(T{} / V{})> operator/(const V& f) const { |
| 101 | return {x / f, y / f}; | 101 | return {x / f, y / f}; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| @@ -107,18 +107,18 @@ public: | |||
| 107 | return *this; | 107 | return *this; |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | constexpr T Length2() const { | 110 | [[nodiscard]] constexpr T Length2() const { |
| 111 | return x * x + y * y; | 111 | return x * x + y * y; |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | // Only implemented for T=float | 114 | // Only implemented for T=float |
| 115 | float Length() const; | 115 | [[nodiscard]] float Length() const; |
| 116 | float Normalize(); // returns the previous length, which is often useful | 116 | [[nodiscard]] float Normalize(); // returns the previous length, which is often useful |
| 117 | 117 | ||
| 118 | constexpr T& operator[](std::size_t i) { | 118 | [[nodiscard]] constexpr T& operator[](std::size_t i) { |
| 119 | return *((&x) + i); | 119 | return *((&x) + i); |
| 120 | } | 120 | } |
| 121 | constexpr const T& operator[](std::size_t i) const { | 121 | [[nodiscard]] constexpr const T& operator[](std::size_t i) const { |
| 122 | return *((&x) + i); | 122 | return *((&x) + i); |
| 123 | } | 123 | } |
| 124 | 124 | ||
| @@ -128,46 +128,46 @@ public: | |||
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | // Common aliases: UV (texel coordinates), ST (texture coordinates) | 130 | // Common aliases: UV (texel coordinates), ST (texture coordinates) |
| 131 | constexpr T& u() { | 131 | [[nodiscard]] constexpr T& u() { |
| 132 | return x; | 132 | return x; |
| 133 | } | 133 | } |
| 134 | constexpr T& v() { | 134 | [[nodiscard]] constexpr T& v() { |
| 135 | return y; | 135 | return y; |
| 136 | } | 136 | } |
| 137 | constexpr T& s() { | 137 | [[nodiscard]] constexpr T& s() { |
| 138 | return x; | 138 | return x; |
| 139 | } | 139 | } |
| 140 | constexpr T& t() { | 140 | [[nodiscard]] constexpr T& t() { |
| 141 | return y; | 141 | return y; |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | constexpr const T& u() const { | 144 | [[nodiscard]] constexpr const T& u() const { |
| 145 | return x; | 145 | return x; |
| 146 | } | 146 | } |
| 147 | constexpr const T& v() const { | 147 | [[nodiscard]] constexpr const T& v() const { |
| 148 | return y; | 148 | return y; |
| 149 | } | 149 | } |
| 150 | constexpr const T& s() const { | 150 | [[nodiscard]] constexpr const T& s() const { |
| 151 | return x; | 151 | return x; |
| 152 | } | 152 | } |
| 153 | constexpr const T& t() const { | 153 | [[nodiscard]] constexpr const T& t() const { |
| 154 | return y; | 154 | return y; |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | // swizzlers - create a subvector of specific components | 157 | // swizzlers - create a subvector of specific components |
| 158 | constexpr Vec2 yx() const { | 158 | [[nodiscard]] constexpr Vec2 yx() const { |
| 159 | return Vec2(y, x); | 159 | return Vec2(y, x); |
| 160 | } | 160 | } |
| 161 | constexpr Vec2 vu() const { | 161 | [[nodiscard]] constexpr Vec2 vu() const { |
| 162 | return Vec2(y, x); | 162 | return Vec2(y, x); |
| 163 | } | 163 | } |
| 164 | constexpr Vec2 ts() const { | 164 | [[nodiscard]] constexpr Vec2 ts() const { |
| 165 | return Vec2(y, x); | 165 | return Vec2(y, x); |
| 166 | } | 166 | } |
| 167 | }; | 167 | }; |
| 168 | 168 | ||
| 169 | template <typename T, typename V> | 169 | template <typename T, typename V> |
| 170 | constexpr Vec2<T> operator*(const V& f, const Vec2<T>& vec) { | 170 | [[nodiscard]] constexpr Vec2<T> operator*(const V& f, const Vec2<T>& vec) { |
| 171 | return Vec2<T>(f * vec.x, f * vec.y); | 171 | return Vec2<T>(f * vec.x, f * vec.y); |
| 172 | } | 172 | } |
| 173 | 173 | ||
| @@ -196,15 +196,15 @@ public: | |||
| 196 | constexpr Vec3(const T& x_, const T& y_, const T& z_) : x(x_), y(y_), z(z_) {} | 196 | constexpr Vec3(const T& x_, const T& y_, const T& z_) : x(x_), y(y_), z(z_) {} |
| 197 | 197 | ||
| 198 | template <typename T2> | 198 | template <typename T2> |
| 199 | constexpr Vec3<T2> Cast() const { | 199 | [[nodiscard]] constexpr Vec3<T2> Cast() const { |
| 200 | return Vec3<T2>(static_cast<T2>(x), static_cast<T2>(y), static_cast<T2>(z)); | 200 | return Vec3<T2>(static_cast<T2>(x), static_cast<T2>(y), static_cast<T2>(z)); |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | static constexpr Vec3 AssignToAll(const T& f) { | 203 | [[nodiscard]] static constexpr Vec3 AssignToAll(const T& f) { |
| 204 | return Vec3(f, f, f); | 204 | return Vec3(f, f, f); |
| 205 | } | 205 | } |
| 206 | 206 | ||
| 207 | constexpr Vec3<decltype(T{} + T{})> operator+(const Vec3& other) const { | 207 | [[nodiscard]] constexpr Vec3<decltype(T{} + T{})> operator+(const Vec3& other) const { |
| 208 | return {x + other.x, y + other.y, z + other.z}; | 208 | return {x + other.x, y + other.y, z + other.z}; |
| 209 | } | 209 | } |
| 210 | 210 | ||
| @@ -215,7 +215,7 @@ public: | |||
| 215 | return *this; | 215 | return *this; |
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | constexpr Vec3<decltype(T{} - T{})> operator-(const Vec3& other) const { | 218 | [[nodiscard]] constexpr Vec3<decltype(T{} - T{})> operator-(const Vec3& other) const { |
| 219 | return {x - other.x, y - other.y, z - other.z}; | 219 | return {x - other.x, y - other.y, z - other.z}; |
| 220 | } | 220 | } |
| 221 | 221 | ||
| @@ -227,16 +227,16 @@ public: | |||
| 227 | } | 227 | } |
| 228 | 228 | ||
| 229 | template <typename U = T> | 229 | template <typename U = T> |
| 230 | constexpr Vec3<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const { | 230 | [[nodiscard]] constexpr Vec3<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const { |
| 231 | return {-x, -y, -z}; | 231 | return {-x, -y, -z}; |
| 232 | } | 232 | } |
| 233 | 233 | ||
| 234 | constexpr Vec3<decltype(T{} * T{})> operator*(const Vec3& other) const { | 234 | [[nodiscard]] constexpr Vec3<decltype(T{} * T{})> operator*(const Vec3& other) const { |
| 235 | return {x * other.x, y * other.y, z * other.z}; | 235 | return {x * other.x, y * other.y, z * other.z}; |
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | template <typename V> | 238 | template <typename V> |
| 239 | constexpr Vec3<decltype(T{} * V{})> operator*(const V& f) const { | 239 | [[nodiscard]] constexpr Vec3<decltype(T{} * V{})> operator*(const V& f) const { |
| 240 | return {x * f, y * f, z * f}; | 240 | return {x * f, y * f, z * f}; |
| 241 | } | 241 | } |
| 242 | 242 | ||
| @@ -246,7 +246,7 @@ public: | |||
| 246 | return *this; | 246 | return *this; |
| 247 | } | 247 | } |
| 248 | template <typename V> | 248 | template <typename V> |
| 249 | constexpr Vec3<decltype(T{} / V{})> operator/(const V& f) const { | 249 | [[nodiscard]] constexpr Vec3<decltype(T{} / V{})> operator/(const V& f) const { |
| 250 | return {x / f, y / f, z / f}; | 250 | return {x / f, y / f, z / f}; |
| 251 | } | 251 | } |
| 252 | 252 | ||
| @@ -256,20 +256,20 @@ public: | |||
| 256 | return *this; | 256 | return *this; |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | constexpr T Length2() const { | 259 | [[nodiscard]] constexpr T Length2() const { |
| 260 | return x * x + y * y + z * z; | 260 | return x * x + y * y + z * z; |
| 261 | } | 261 | } |
| 262 | 262 | ||
| 263 | // Only implemented for T=float | 263 | // Only implemented for T=float |
| 264 | float Length() const; | 264 | [[nodiscard]] float Length() const; |
| 265 | Vec3 Normalized() const; | 265 | [[nodiscard]] Vec3 Normalized() const; |
| 266 | float Normalize(); // returns the previous length, which is often useful | 266 | [[nodiscard]] float Normalize(); // returns the previous length, which is often useful |
| 267 | 267 | ||
| 268 | constexpr T& operator[](std::size_t i) { | 268 | [[nodiscard]] constexpr T& operator[](std::size_t i) { |
| 269 | return *((&x) + i); | 269 | return *((&x) + i); |
| 270 | } | 270 | } |
| 271 | 271 | ||
| 272 | constexpr const T& operator[](std::size_t i) const { | 272 | [[nodiscard]] constexpr const T& operator[](std::size_t i) const { |
| 273 | return *((&x) + i); | 273 | return *((&x) + i); |
| 274 | } | 274 | } |
| 275 | 275 | ||
| @@ -280,63 +280,63 @@ public: | |||
| 280 | } | 280 | } |
| 281 | 281 | ||
| 282 | // Common aliases: UVW (texel coordinates), RGB (colors), STQ (texture coordinates) | 282 | // Common aliases: UVW (texel coordinates), RGB (colors), STQ (texture coordinates) |
| 283 | constexpr T& u() { | 283 | [[nodiscard]] constexpr T& u() { |
| 284 | return x; | 284 | return x; |
| 285 | } | 285 | } |
| 286 | constexpr T& v() { | 286 | [[nodiscard]] constexpr T& v() { |
| 287 | return y; | 287 | return y; |
| 288 | } | 288 | } |
| 289 | constexpr T& w() { | 289 | [[nodiscard]] constexpr T& w() { |
| 290 | return z; | 290 | return z; |
| 291 | } | 291 | } |
| 292 | 292 | ||
| 293 | constexpr T& r() { | 293 | [[nodiscard]] constexpr T& r() { |
| 294 | return x; | 294 | return x; |
| 295 | } | 295 | } |
| 296 | constexpr T& g() { | 296 | [[nodiscard]] constexpr T& g() { |
| 297 | return y; | 297 | return y; |
| 298 | } | 298 | } |
| 299 | constexpr T& b() { | 299 | [[nodiscard]] constexpr T& b() { |
| 300 | return z; | 300 | return z; |
| 301 | } | 301 | } |
| 302 | 302 | ||
| 303 | constexpr T& s() { | 303 | [[nodiscard]] constexpr T& s() { |
| 304 | return x; | 304 | return x; |
| 305 | } | 305 | } |
| 306 | constexpr T& t() { | 306 | [[nodiscard]] constexpr T& t() { |
| 307 | return y; | 307 | return y; |
| 308 | } | 308 | } |
| 309 | constexpr T& q() { | 309 | [[nodiscard]] constexpr T& q() { |
| 310 | return z; | 310 | return z; |
| 311 | } | 311 | } |
| 312 | 312 | ||
| 313 | constexpr const T& u() const { | 313 | [[nodiscard]] constexpr const T& u() const { |
| 314 | return x; | 314 | return x; |
| 315 | } | 315 | } |
| 316 | constexpr const T& v() const { | 316 | [[nodiscard]] constexpr const T& v() const { |
| 317 | return y; | 317 | return y; |
| 318 | } | 318 | } |
| 319 | constexpr const T& w() const { | 319 | [[nodiscard]] constexpr const T& w() const { |
| 320 | return z; | 320 | return z; |
| 321 | } | 321 | } |
| 322 | 322 | ||
| 323 | constexpr const T& r() const { | 323 | [[nodiscard]] constexpr const T& r() const { |
| 324 | return x; | 324 | return x; |
| 325 | } | 325 | } |
| 326 | constexpr const T& g() const { | 326 | [[nodiscard]] constexpr const T& g() const { |
| 327 | return y; | 327 | return y; |
| 328 | } | 328 | } |
| 329 | constexpr const T& b() const { | 329 | [[nodiscard]] constexpr const T& b() const { |
| 330 | return z; | 330 | return z; |
| 331 | } | 331 | } |
| 332 | 332 | ||
| 333 | constexpr const T& s() const { | 333 | [[nodiscard]] constexpr const T& s() const { |
| 334 | return x; | 334 | return x; |
| 335 | } | 335 | } |
| 336 | constexpr const T& t() const { | 336 | [[nodiscard]] constexpr const T& t() const { |
| 337 | return y; | 337 | return y; |
| 338 | } | 338 | } |
| 339 | constexpr const T& q() const { | 339 | [[nodiscard]] constexpr const T& q() const { |
| 340 | return z; | 340 | return z; |
| 341 | } | 341 | } |
| 342 | 342 | ||
| @@ -345,7 +345,7 @@ public: | |||
| 345 | // _DEFINE_SWIZZLER2 defines a single such function, DEFINE_SWIZZLER2 defines all of them for all | 345 | // _DEFINE_SWIZZLER2 defines a single such function, DEFINE_SWIZZLER2 defines all of them for all |
| 346 | // component names (x<->r) and permutations (xy<->yx) | 346 | // component names (x<->r) and permutations (xy<->yx) |
| 347 | #define _DEFINE_SWIZZLER2(a, b, name) \ | 347 | #define _DEFINE_SWIZZLER2(a, b, name) \ |
| 348 | constexpr Vec2<T> name() const { \ | 348 | [[nodiscard]] constexpr Vec2<T> name() const { \ |
| 349 | return Vec2<T>(a, b); \ | 349 | return Vec2<T>(a, b); \ |
| 350 | } | 350 | } |
| 351 | #define DEFINE_SWIZZLER2(a, b, a2, b2, a3, b3, a4, b4) \ | 351 | #define DEFINE_SWIZZLER2(a, b, a2, b2, a3, b3, a4, b4) \ |
| @@ -366,7 +366,7 @@ public: | |||
| 366 | }; | 366 | }; |
| 367 | 367 | ||
| 368 | template <typename T, typename V> | 368 | template <typename T, typename V> |
| 369 | constexpr Vec3<T> operator*(const V& f, const Vec3<T>& vec) { | 369 | [[nodiscard]] constexpr Vec3<T> operator*(const V& f, const Vec3<T>& vec) { |
| 370 | return Vec3<T>(f * vec.x, f * vec.y, f * vec.z); | 370 | return Vec3<T>(f * vec.x, f * vec.y, f * vec.z); |
| 371 | } | 371 | } |
| 372 | 372 | ||
| @@ -402,16 +402,16 @@ public: | |||
| 402 | : x(x_), y(y_), z(z_), w(w_) {} | 402 | : x(x_), y(y_), z(z_), w(w_) {} |
| 403 | 403 | ||
| 404 | template <typename T2> | 404 | template <typename T2> |
| 405 | constexpr Vec4<T2> Cast() const { | 405 | [[nodiscard]] constexpr Vec4<T2> Cast() const { |
| 406 | return Vec4<T2>(static_cast<T2>(x), static_cast<T2>(y), static_cast<T2>(z), | 406 | return Vec4<T2>(static_cast<T2>(x), static_cast<T2>(y), static_cast<T2>(z), |
| 407 | static_cast<T2>(w)); | 407 | static_cast<T2>(w)); |
| 408 | } | 408 | } |
| 409 | 409 | ||
| 410 | static constexpr Vec4 AssignToAll(const T& f) { | 410 | [[nodiscard]] static constexpr Vec4 AssignToAll(const T& f) { |
| 411 | return Vec4(f, f, f, f); | 411 | return Vec4(f, f, f, f); |
| 412 | } | 412 | } |
| 413 | 413 | ||
| 414 | constexpr Vec4<decltype(T{} + T{})> operator+(const Vec4& other) const { | 414 | [[nodiscard]] constexpr Vec4<decltype(T{} + T{})> operator+(const Vec4& other) const { |
| 415 | return {x + other.x, y + other.y, z + other.z, w + other.w}; | 415 | return {x + other.x, y + other.y, z + other.z, w + other.w}; |
| 416 | } | 416 | } |
| 417 | 417 | ||
| @@ -423,7 +423,7 @@ public: | |||
| 423 | return *this; | 423 | return *this; |
| 424 | } | 424 | } |
| 425 | 425 | ||
| 426 | constexpr Vec4<decltype(T{} - T{})> operator-(const Vec4& other) const { | 426 | [[nodiscard]] constexpr Vec4<decltype(T{} - T{})> operator-(const Vec4& other) const { |
| 427 | return {x - other.x, y - other.y, z - other.z, w - other.w}; | 427 | return {x - other.x, y - other.y, z - other.z, w - other.w}; |
| 428 | } | 428 | } |
| 429 | 429 | ||
| @@ -436,16 +436,16 @@ public: | |||
| 436 | } | 436 | } |
| 437 | 437 | ||
| 438 | template <typename U = T> | 438 | template <typename U = T> |
| 439 | constexpr Vec4<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const { | 439 | [[nodiscard]] constexpr Vec4<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const { |
| 440 | return {-x, -y, -z, -w}; | 440 | return {-x, -y, -z, -w}; |
| 441 | } | 441 | } |
| 442 | 442 | ||
| 443 | constexpr Vec4<decltype(T{} * T{})> operator*(const Vec4& other) const { | 443 | [[nodiscard]] constexpr Vec4<decltype(T{} * T{})> operator*(const Vec4& other) const { |
| 444 | return {x * other.x, y * other.y, z * other.z, w * other.w}; | 444 | return {x * other.x, y * other.y, z * other.z, w * other.w}; |
| 445 | } | 445 | } |
| 446 | 446 | ||
| 447 | template <typename V> | 447 | template <typename V> |
| 448 | constexpr Vec4<decltype(T{} * V{})> operator*(const V& f) const { | 448 | [[nodiscard]] constexpr Vec4<decltype(T{} * V{})> operator*(const V& f) const { |
| 449 | return {x * f, y * f, z * f, w * f}; | 449 | return {x * f, y * f, z * f, w * f}; |
| 450 | } | 450 | } |
| 451 | 451 | ||
| @@ -456,7 +456,7 @@ public: | |||
| 456 | } | 456 | } |
| 457 | 457 | ||
| 458 | template <typename V> | 458 | template <typename V> |
| 459 | constexpr Vec4<decltype(T{} / V{})> operator/(const V& f) const { | 459 | [[nodiscard]] constexpr Vec4<decltype(T{} / V{})> operator/(const V& f) const { |
| 460 | return {x / f, y / f, z / f, w / f}; | 460 | return {x / f, y / f, z / f, w / f}; |
| 461 | } | 461 | } |
| 462 | 462 | ||
| @@ -466,15 +466,15 @@ public: | |||
| 466 | return *this; | 466 | return *this; |
| 467 | } | 467 | } |
| 468 | 468 | ||
| 469 | constexpr T Length2() const { | 469 | [[nodiscard]] constexpr T Length2() const { |
| 470 | return x * x + y * y + z * z + w * w; | 470 | return x * x + y * y + z * z + w * w; |
| 471 | } | 471 | } |
| 472 | 472 | ||
| 473 | constexpr T& operator[](std::size_t i) { | 473 | [[nodiscard]] constexpr T& operator[](std::size_t i) { |
| 474 | return *((&x) + i); | 474 | return *((&x) + i); |
| 475 | } | 475 | } |
| 476 | 476 | ||
| 477 | constexpr const T& operator[](std::size_t i) const { | 477 | [[nodiscard]] constexpr const T& operator[](std::size_t i) const { |
| 478 | return *((&x) + i); | 478 | return *((&x) + i); |
| 479 | } | 479 | } |
| 480 | 480 | ||
| @@ -486,29 +486,29 @@ public: | |||
| 486 | } | 486 | } |
| 487 | 487 | ||
| 488 | // Common alias: RGBA (colors) | 488 | // Common alias: RGBA (colors) |
| 489 | constexpr T& r() { | 489 | [[nodiscard]] constexpr T& r() { |
| 490 | return x; | 490 | return x; |
| 491 | } | 491 | } |
| 492 | constexpr T& g() { | 492 | [[nodiscard]] constexpr T& g() { |
| 493 | return y; | 493 | return y; |
| 494 | } | 494 | } |
| 495 | constexpr T& b() { | 495 | [[nodiscard]] constexpr T& b() { |
| 496 | return z; | 496 | return z; |
| 497 | } | 497 | } |
| 498 | constexpr T& a() { | 498 | [[nodiscard]] constexpr T& a() { |
| 499 | return w; | 499 | return w; |
| 500 | } | 500 | } |
| 501 | 501 | ||
| 502 | constexpr const T& r() const { | 502 | [[nodiscard]] constexpr const T& r() const { |
| 503 | return x; | 503 | return x; |
| 504 | } | 504 | } |
| 505 | constexpr const T& g() const { | 505 | [[nodiscard]] constexpr const T& g() const { |
| 506 | return y; | 506 | return y; |
| 507 | } | 507 | } |
| 508 | constexpr const T& b() const { | 508 | [[nodiscard]] constexpr const T& b() const { |
| 509 | return z; | 509 | return z; |
| 510 | } | 510 | } |
| 511 | constexpr const T& a() const { | 511 | [[nodiscard]] constexpr const T& a() const { |
| 512 | return w; | 512 | return w; |
| 513 | } | 513 | } |
| 514 | 514 | ||
| @@ -520,7 +520,7 @@ public: | |||
| 520 | // DEFINE_SWIZZLER2_COMP2 defines two component functions for all component names (x<->r) and | 520 | // DEFINE_SWIZZLER2_COMP2 defines two component functions for all component names (x<->r) and |
| 521 | // permutations (xy<->yx) | 521 | // permutations (xy<->yx) |
| 522 | #define _DEFINE_SWIZZLER2(a, b, name) \ | 522 | #define _DEFINE_SWIZZLER2(a, b, name) \ |
| 523 | constexpr Vec2<T> name() const { \ | 523 | [[nodiscard]] constexpr Vec2<T> name() const { \ |
| 524 | return Vec2<T>(a, b); \ | 524 | return Vec2<T>(a, b); \ |
| 525 | } | 525 | } |
| 526 | #define DEFINE_SWIZZLER2_COMP1(a, a2) \ | 526 | #define DEFINE_SWIZZLER2_COMP1(a, a2) \ |
| @@ -547,7 +547,7 @@ public: | |||
| 547 | #undef _DEFINE_SWIZZLER2 | 547 | #undef _DEFINE_SWIZZLER2 |
| 548 | 548 | ||
| 549 | #define _DEFINE_SWIZZLER3(a, b, c, name) \ | 549 | #define _DEFINE_SWIZZLER3(a, b, c, name) \ |
| 550 | constexpr Vec3<T> name() const { \ | 550 | [[nodiscard]] constexpr Vec3<T> name() const { \ |
| 551 | return Vec3<T>(a, b, c); \ | 551 | return Vec3<T>(a, b, c); \ |
| 552 | } | 552 | } |
| 553 | #define DEFINE_SWIZZLER3_COMP1(a, a2) \ | 553 | #define DEFINE_SWIZZLER3_COMP1(a, a2) \ |
| @@ -581,7 +581,7 @@ public: | |||
| 581 | }; | 581 | }; |
| 582 | 582 | ||
| 583 | template <typename T, typename V> | 583 | template <typename T, typename V> |
| 584 | constexpr Vec4<decltype(V{} * T{})> operator*(const V& f, const Vec4<T>& vec) { | 584 | [[nodiscard]] constexpr Vec4<decltype(V{} * T{})> operator*(const V& f, const Vec4<T>& vec) { |
| 585 | return {f * vec.x, f * vec.y, f * vec.z, f * vec.w}; | 585 | return {f * vec.x, f * vec.y, f * vec.z, f * vec.w}; |
| 586 | } | 586 | } |
| 587 | 587 | ||
| @@ -593,39 +593,41 @@ constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec2<T>& a, const Vec2<T>& b | |||
| 593 | } | 593 | } |
| 594 | 594 | ||
| 595 | template <typename T> | 595 | template <typename T> |
| 596 | constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec3<T>& a, const Vec3<T>& b) { | 596 | [[nodiscard]] constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec3<T>& a, const Vec3<T>& b) { |
| 597 | return a.x * b.x + a.y * b.y + a.z * b.z; | 597 | return a.x * b.x + a.y * b.y + a.z * b.z; |
| 598 | } | 598 | } |
| 599 | 599 | ||
| 600 | template <typename T> | 600 | template <typename T> |
| 601 | constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec4<T>& a, const Vec4<T>& b) { | 601 | [[nodiscard]] constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec4<T>& a, const Vec4<T>& b) { |
| 602 | return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; | 602 | return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; |
| 603 | } | 603 | } |
| 604 | 604 | ||
| 605 | template <typename T> | 605 | template <typename T> |
| 606 | constexpr Vec3<decltype(T{} * T{} - T{} * T{})> Cross(const Vec3<T>& a, const Vec3<T>& b) { | 606 | [[nodiscard]] constexpr Vec3<decltype(T{} * T{} - T{} * T{})> Cross(const Vec3<T>& a, |
| 607 | const Vec3<T>& b) { | ||
| 607 | return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; | 608 | return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; |
| 608 | } | 609 | } |
| 609 | 610 | ||
| 610 | // linear interpolation via float: 0.0=begin, 1.0=end | 611 | // linear interpolation via float: 0.0=begin, 1.0=end |
| 611 | template <typename X> | 612 | template <typename X> |
| 612 | constexpr decltype(X{} * float{} + X{} * float{}) Lerp(const X& begin, const X& end, | 613 | [[nodiscard]] constexpr decltype(X{} * float{} + X{} * float{}) Lerp(const X& begin, const X& end, |
| 613 | const float t) { | 614 | const float t) { |
| 614 | return begin * (1.f - t) + end * t; | 615 | return begin * (1.f - t) + end * t; |
| 615 | } | 616 | } |
| 616 | 617 | ||
| 617 | // linear interpolation via int: 0=begin, base=end | 618 | // linear interpolation via int: 0=begin, base=end |
| 618 | template <typename X, int base> | 619 | template <typename X, int base> |
| 619 | constexpr decltype((X{} * int{} + X{} * int{}) / base) LerpInt(const X& begin, const X& end, | 620 | [[nodiscard]] constexpr decltype((X{} * int{} + X{} * int{}) / base) LerpInt(const X& begin, |
| 620 | const int t) { | 621 | const X& end, |
| 622 | const int t) { | ||
| 621 | return (begin * (base - t) + end * t) / base; | 623 | return (begin * (base - t) + end * t) / base; |
| 622 | } | 624 | } |
| 623 | 625 | ||
| 624 | // bilinear interpolation. s is for interpolating x00-x01 and x10-x11, and t is for the second | 626 | // bilinear interpolation. s is for interpolating x00-x01 and x10-x11, and t is for the second |
| 625 | // interpolation. | 627 | // interpolation. |
| 626 | template <typename X> | 628 | template <typename X> |
| 627 | constexpr auto BilinearInterp(const X& x00, const X& x01, const X& x10, const X& x11, const float s, | 629 | [[nodiscard]] constexpr auto BilinearInterp(const X& x00, const X& x01, const X& x10, const X& x11, |
| 628 | const float t) { | 630 | const float s, const float t) { |
| 629 | auto y0 = Lerp(x00, x01, s); | 631 | auto y0 = Lerp(x00, x01, s); |
| 630 | auto y1 = Lerp(x10, x11, s); | 632 | auto y1 = Lerp(x10, x11, s); |
| 631 | return Lerp(y0, y1, t); | 633 | return Lerp(y0, y1, t); |
| @@ -633,42 +635,42 @@ constexpr auto BilinearInterp(const X& x00, const X& x01, const X& x10, const X& | |||
| 633 | 635 | ||
| 634 | // Utility vector factories | 636 | // Utility vector factories |
| 635 | template <typename T> | 637 | template <typename T> |
| 636 | constexpr Vec2<T> MakeVec(const T& x, const T& y) { | 638 | [[nodiscard]] constexpr Vec2<T> MakeVec(const T& x, const T& y) { |
| 637 | return Vec2<T>{x, y}; | 639 | return Vec2<T>{x, y}; |
| 638 | } | 640 | } |
| 639 | 641 | ||
| 640 | template <typename T> | 642 | template <typename T> |
| 641 | constexpr Vec3<T> MakeVec(const T& x, const T& y, const T& z) { | 643 | [[nodiscard]] constexpr Vec3<T> MakeVec(const T& x, const T& y, const T& z) { |
| 642 | return Vec3<T>{x, y, z}; | 644 | return Vec3<T>{x, y, z}; |
| 643 | } | 645 | } |
| 644 | 646 | ||
| 645 | template <typename T> | 647 | template <typename T> |
| 646 | constexpr Vec4<T> MakeVec(const T& x, const T& y, const Vec2<T>& zw) { | 648 | [[nodiscard]] constexpr Vec4<T> MakeVec(const T& x, const T& y, const Vec2<T>& zw) { |
| 647 | return MakeVec(x, y, zw[0], zw[1]); | 649 | return MakeVec(x, y, zw[0], zw[1]); |
| 648 | } | 650 | } |
| 649 | 651 | ||
| 650 | template <typename T> | 652 | template <typename T> |
| 651 | constexpr Vec3<T> MakeVec(const Vec2<T>& xy, const T& z) { | 653 | [[nodiscard]] constexpr Vec3<T> MakeVec(const Vec2<T>& xy, const T& z) { |
| 652 | return MakeVec(xy[0], xy[1], z); | 654 | return MakeVec(xy[0], xy[1], z); |
| 653 | } | 655 | } |
| 654 | 656 | ||
| 655 | template <typename T> | 657 | template <typename T> |
| 656 | constexpr Vec3<T> MakeVec(const T& x, const Vec2<T>& yz) { | 658 | [[nodiscard]] constexpr Vec3<T> MakeVec(const T& x, const Vec2<T>& yz) { |
| 657 | return MakeVec(x, yz[0], yz[1]); | 659 | return MakeVec(x, yz[0], yz[1]); |
| 658 | } | 660 | } |
| 659 | 661 | ||
| 660 | template <typename T> | 662 | template <typename T> |
| 661 | constexpr Vec4<T> MakeVec(const T& x, const T& y, const T& z, const T& w) { | 663 | [[nodiscard]] constexpr Vec4<T> MakeVec(const T& x, const T& y, const T& z, const T& w) { |
| 662 | return Vec4<T>{x, y, z, w}; | 664 | return Vec4<T>{x, y, z, w}; |
| 663 | } | 665 | } |
| 664 | 666 | ||
| 665 | template <typename T> | 667 | template <typename T> |
| 666 | constexpr Vec4<T> MakeVec(const Vec2<T>& xy, const T& z, const T& w) { | 668 | [[nodiscard]] constexpr Vec4<T> MakeVec(const Vec2<T>& xy, const T& z, const T& w) { |
| 667 | return MakeVec(xy[0], xy[1], z, w); | 669 | return MakeVec(xy[0], xy[1], z, w); |
| 668 | } | 670 | } |
| 669 | 671 | ||
| 670 | template <typename T> | 672 | template <typename T> |
| 671 | constexpr Vec4<T> MakeVec(const T& x, const Vec2<T>& yz, const T& w) { | 673 | [[nodiscard]] constexpr Vec4<T> MakeVec(const T& x, const Vec2<T>& yz, const T& w) { |
| 672 | return MakeVec(x, yz[0], yz[1], w); | 674 | return MakeVec(x, yz[0], yz[1], w); |
| 673 | } | 675 | } |
| 674 | 676 | ||
| @@ -676,17 +678,17 @@ constexpr Vec4<T> MakeVec(const T& x, const Vec2<T>& yz, const T& w) { | |||
| 676 | // Even if someone wanted to use an odd object like Vec2<Vec2<T>>, the compiler would error | 678 | // Even if someone wanted to use an odd object like Vec2<Vec2<T>>, the compiler would error |
| 677 | // out soon enough due to misuse of the returned structure. | 679 | // out soon enough due to misuse of the returned structure. |
| 678 | template <typename T> | 680 | template <typename T> |
| 679 | constexpr Vec4<T> MakeVec(const Vec2<T>& xy, const Vec2<T>& zw) { | 681 | [[nodiscard]] constexpr Vec4<T> MakeVec(const Vec2<T>& xy, const Vec2<T>& zw) { |
| 680 | return MakeVec(xy[0], xy[1], zw[0], zw[1]); | 682 | return MakeVec(xy[0], xy[1], zw[0], zw[1]); |
| 681 | } | 683 | } |
| 682 | 684 | ||
| 683 | template <typename T> | 685 | template <typename T> |
| 684 | constexpr Vec4<T> MakeVec(const Vec3<T>& xyz, const T& w) { | 686 | [[nodiscard]] constexpr Vec4<T> MakeVec(const Vec3<T>& xyz, const T& w) { |
| 685 | return MakeVec(xyz[0], xyz[1], xyz[2], w); | 687 | return MakeVec(xyz[0], xyz[1], xyz[2], w); |
| 686 | } | 688 | } |
| 687 | 689 | ||
| 688 | template <typename T> | 690 | template <typename T> |
| 689 | constexpr Vec4<T> MakeVec(const T& x, const Vec3<T>& yzw) { | 691 | [[nodiscard]] constexpr Vec4<T> MakeVec(const T& x, const Vec3<T>& yzw) { |
| 690 | return MakeVec(x, yzw[0], yzw[1], yzw[2]); | 692 | return MakeVec(x, yzw[0], yzw[1], yzw[2]); |
| 691 | } | 693 | } |
| 692 | 694 | ||
diff --git a/src/common/virtual_buffer.h b/src/common/virtual_buffer.h index da064e59e..125cb42f0 100644 --- a/src/common/virtual_buffer.h +++ b/src/common/virtual_buffer.h | |||
| @@ -30,23 +30,23 @@ public: | |||
| 30 | base_ptr = reinterpret_cast<T*>(AllocateMemoryPages(alloc_size)); | 30 | base_ptr = reinterpret_cast<T*>(AllocateMemoryPages(alloc_size)); |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | constexpr const T& operator[](std::size_t index) const { | 33 | [[nodiscard]] constexpr const T& operator[](std::size_t index) const { |
| 34 | return base_ptr[index]; | 34 | return base_ptr[index]; |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | constexpr T& operator[](std::size_t index) { | 37 | [[nodiscard]] constexpr T& operator[](std::size_t index) { |
| 38 | return base_ptr[index]; | 38 | return base_ptr[index]; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | constexpr T* data() { | 41 | [[nodiscard]] constexpr T* data() { |
| 42 | return base_ptr; | 42 | return base_ptr; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | constexpr const T* data() const { | 45 | [[nodiscard]] constexpr const T* data() const { |
| 46 | return base_ptr; | 46 | return base_ptr; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | constexpr std::size_t size() const { | 49 | [[nodiscard]] constexpr std::size_t size() const { |
| 50 | return alloc_size / sizeof(T); | 50 | return alloc_size / sizeof(T); |
| 51 | } | 51 | } |
| 52 | 52 | ||
diff --git a/src/common/wall_clock.h b/src/common/wall_clock.h index 367d72134..5db30083d 100644 --- a/src/common/wall_clock.h +++ b/src/common/wall_clock.h | |||
| @@ -14,24 +14,24 @@ namespace Common { | |||
| 14 | class WallClock { | 14 | class WallClock { |
| 15 | public: | 15 | public: |
| 16 | /// Returns current wall time in nanoseconds | 16 | /// Returns current wall time in nanoseconds |
| 17 | virtual std::chrono::nanoseconds GetTimeNS() = 0; | 17 | [[nodiscard]] virtual std::chrono::nanoseconds GetTimeNS() = 0; |
| 18 | 18 | ||
| 19 | /// Returns current wall time in microseconds | 19 | /// Returns current wall time in microseconds |
| 20 | virtual std::chrono::microseconds GetTimeUS() = 0; | 20 | [[nodiscard]] virtual std::chrono::microseconds GetTimeUS() = 0; |
| 21 | 21 | ||
| 22 | /// Returns current wall time in milliseconds | 22 | /// Returns current wall time in milliseconds |
| 23 | virtual std::chrono::milliseconds GetTimeMS() = 0; | 23 | [[nodiscard]] virtual std::chrono::milliseconds GetTimeMS() = 0; |
| 24 | 24 | ||
| 25 | /// Returns current wall time in emulated clock cycles | 25 | /// Returns current wall time in emulated clock cycles |
| 26 | virtual u64 GetClockCycles() = 0; | 26 | [[nodiscard]] virtual u64 GetClockCycles() = 0; |
| 27 | 27 | ||
| 28 | /// Returns current wall time in emulated cpu cycles | 28 | /// Returns current wall time in emulated cpu cycles |
| 29 | virtual u64 GetCPUCycles() = 0; | 29 | [[nodiscard]] virtual u64 GetCPUCycles() = 0; |
| 30 | 30 | ||
| 31 | virtual void Pause(bool is_paused) = 0; | 31 | virtual void Pause(bool is_paused) = 0; |
| 32 | 32 | ||
| 33 | /// Tells if the wall clock, uses the host CPU's hardware clock | 33 | /// Tells if the wall clock, uses the host CPU's hardware clock |
| 34 | bool IsNative() const { | 34 | [[nodiscard]] bool IsNative() const { |
| 35 | return is_native; | 35 | return is_native; |
| 36 | } | 36 | } |
| 37 | 37 | ||
| @@ -47,7 +47,7 @@ private: | |||
| 47 | bool is_native; | 47 | bool is_native; |
| 48 | }; | 48 | }; |
| 49 | 49 | ||
| 50 | std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency, | 50 | [[nodiscard]] std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency, |
| 51 | u32 emulated_clock_frequency); | 51 | u32 emulated_clock_frequency); |
| 52 | 52 | ||
| 53 | } // namespace Common | 53 | } // namespace Common |
diff --git a/src/common/zstd_compression.h b/src/common/zstd_compression.h index b5edf19e7..4bacf8355 100644 --- a/src/common/zstd_compression.h +++ b/src/common/zstd_compression.h | |||
| @@ -19,7 +19,7 @@ namespace Common::Compression { | |||
| 19 | * | 19 | * |
| 20 | * @return the compressed data. | 20 | * @return the compressed data. |
| 21 | */ | 21 | */ |
| 22 | std::vector<u8> CompressDataZSTD(std::span<const u8> source, s32 compression_level); | 22 | [[nodiscard]] std::vector<u8> CompressDataZSTD(std::span<const u8> source, s32 compression_level); |
| 23 | 23 | ||
| 24 | /** | 24 | /** |
| 25 | * Compresses a source memory region with Zstandard with the default compression level and returns | 25 | * Compresses a source memory region with Zstandard with the default compression level and returns |
| @@ -29,7 +29,7 @@ std::vector<u8> CompressDataZSTD(std::span<const u8> source, s32 compression_lev | |||
| 29 | * | 29 | * |
| 30 | * @return the compressed data. | 30 | * @return the compressed data. |
| 31 | */ | 31 | */ |
| 32 | std::vector<u8> CompressDataZSTDDefault(std::span<const u8> source); | 32 | [[nodiscard]] std::vector<u8> CompressDataZSTDDefault(std::span<const u8> source); |
| 33 | 33 | ||
| 34 | /** | 34 | /** |
| 35 | * Decompresses a source memory region with Zstandard and returns the uncompressed data in a vector. | 35 | * Decompresses a source memory region with Zstandard and returns the uncompressed data in a vector. |
| @@ -38,6 +38,6 @@ std::vector<u8> CompressDataZSTDDefault(std::span<const u8> source); | |||
| 38 | * | 38 | * |
| 39 | * @return the decompressed data. | 39 | * @return the decompressed data. |
| 40 | */ | 40 | */ |
| 41 | std::vector<u8> DecompressDataZSTD(const std::vector<u8>& compressed); | 41 | [[nodiscard]] std::vector<u8> DecompressDataZSTD(const std::vector<u8>& compressed); |
| 42 | 42 | ||
| 43 | } // namespace Common::Compression \ No newline at end of file | 43 | } // namespace Common::Compression \ No newline at end of file |