diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-09-25 20:06:50 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-09-25 20:06:50 +0000 |
commit | 30dc6aaf878b2c55efcf7598fdb8886e06d14e01 (patch) | |
tree | 2de58de8c2eddd4efb5dc8a8c5b54cd3faad4972 /core/fxcrt/fx_memory.h | |
parent | 958142efa4561b5efd52733ad6c3b889cf49b3ae (diff) | |
download | pdfium-30dc6aaf878b2c55efcf7598fdb8886e06d14e01.tar.xz |
Add FxAlignToBoundary<>() template helper function.
Because I nearly botched this trivial calculation in the previous CL.
Change-Id: I7438f9d3476d93b7899c2d7d761234769f53f9e3
Reviewed-on: https://pdfium-review.googlesource.com/43010
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcrt/fx_memory.h')
-rw-r--r-- | core/fxcrt/fx_memory.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/core/fxcrt/fx_memory.h b/core/fxcrt/fx_memory.h index 707e084211..b39911269b 100644 --- a/core/fxcrt/fx_memory.h +++ b/core/fxcrt/fx_memory.h @@ -130,6 +130,13 @@ inline void FX_Free(void* ptr) { template <typename T, size_t N> char (&ArraySizeHelper(T (&array)[N]))[N]; +// Round up to the power-of-two boundary N. +template <int N, typename T> +inline T FxAlignToBoundary(T size) { + static_assert(N > 0 && (N & (N - 1)) == 0, "Not non-zero power of two"); + return (size + N - 1) & ~(N - 1); +} + // Used with std::unique_ptr to FX_Free raw memory. struct FxFreeDeleter { inline void operator()(void* ptr) const { FX_Free(ptr); } |