mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-08 13:43:33 +01:00
Merge pull request #12010 from TellowKrinkle/AlignUpOpt
Common: Better AlignUp implementation
This commit is contained in:
commit
ff324ef660
@ -7,12 +7,6 @@
|
|||||||
|
|
||||||
namespace Common
|
namespace Common
|
||||||
{
|
{
|
||||||
template <typename T>
|
|
||||||
constexpr T AlignUp(T value, size_t size)
|
|
||||||
{
|
|
||||||
static_assert(std::is_unsigned<T>(), "T must be an unsigned value.");
|
|
||||||
return static_cast<T>(value + (size - value % size) % size);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr T AlignDown(T value, size_t size)
|
constexpr T AlignDown(T value, size_t size)
|
||||||
@ -21,4 +15,11 @@ constexpr T AlignDown(T value, size_t size)
|
|||||||
return static_cast<T>(value - value % size);
|
return static_cast<T>(value - value % size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T AlignUp(T value, size_t size)
|
||||||
|
{
|
||||||
|
static_assert(std::is_unsigned<T>(), "T must be an unsigned value.");
|
||||||
|
return AlignDown<T>(static_cast<T>(value + (size - 1)), size);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
Loading…
x
Reference in New Issue
Block a user