From bcfdf9ffa7c17f5f080b5a45d17497be7d1a28f9 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 7 Sep 2019 15:39:26 +0200 Subject: [PATCH] AK: Add a useful align_up_to(value, power_of_two) function --- AK/Types.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/AK/Types.h b/AK/Types.h index be93bedd63f..c90299d2bdf 100644 --- a/AK/Types.h +++ b/AK/Types.h @@ -73,4 +73,9 @@ static_assert(explode_byte(0x80) == 0x80808080); static_assert(explode_byte(0x7f) == 0x7f7f7f7f); static_assert(explode_byte(0) == 0); +inline constexpr size_t align_up_to(const size_t value, const size_t alignment) +{ + return (value + (alignment - 1)) & ~(alignment - 1); +} + enum class TriState : u8 { False, True, Unknown };