system/core
Revision | 59e7d4e8ea46ec4adf0dbe0fc9f801db98f1d5c6 (tree) |
---|---|
Time | 2019-11-07 08:55:08 |
Author | Steven Moreland <smoreland@goog...> |
Commiter | android-build-merger |
FlattenableUtils::align memsets
am: e62a9d7669
Change-Id: I51a5528d8544f374ff3ceb632e75a1d3ae97d963
@@ -47,7 +47,12 @@ public: | ||
47 | 47 | |
48 | 48 | template<size_t N> |
49 | 49 | static size_t align(void*& buffer) { |
50 | - return align<N>( const_cast<void const*&>(buffer) ); | |
50 | + static_assert(!(N & (N - 1)), "Can only align to a power of 2."); | |
51 | + void* b = buffer; | |
52 | + buffer = reinterpret_cast<void*>((uintptr_t(buffer) + (N-1)) & ~(N-1)); | |
53 | + size_t delta = size_t(uintptr_t(buffer) - uintptr_t(b)); | |
54 | + memset(b, 0, delta); | |
55 | + return delta; | |
51 | 56 | } |
52 | 57 | |
53 | 58 | static void advance(void*& buffer, size_t& size, size_t offset) { |