@@ -109,9 +109,6 @@ class Block {
109109 static constexpr size_t SIZE_MASK = ~(PREV_FREE_MASK | LAST_MASK);
110110
111111public:
112- static constexpr size_t ALIGNMENT = cpp::max(alignof (max_align_t ), size_t {4 });
113- static const size_t BLOCK_OVERHEAD;
114-
115112 // No copy or move.
116113 Block (const Block &other) = delete ;
117114 Block &operator =(const Block &other) = delete ;
@@ -130,19 +127,19 @@ class Block {
130127 // / pointer will return a non-null pointer.
131128 LIBC_INLINE static Block *from_usable_space (void *usable_space) {
132129 auto *bytes = reinterpret_cast <cpp::byte *>(usable_space);
133- return reinterpret_cast <Block *>(bytes - BLOCK_OVERHEAD );
130+ return reinterpret_cast <Block *>(bytes - sizeof (Block) );
134131 }
135132 LIBC_INLINE static const Block *from_usable_space (const void *usable_space) {
136133 const auto *bytes = reinterpret_cast <const cpp::byte *>(usable_space);
137- return reinterpret_cast <const Block *>(bytes - BLOCK_OVERHEAD );
134+ return reinterpret_cast <const Block *>(bytes - sizeof (Block) );
138135 }
139136
140137 // / @returns The total size of the block in bytes, including the header.
141138 LIBC_INLINE size_t outer_size () const { return next_ & SIZE_MASK; }
142139
143140 LIBC_INLINE static size_t outer_size (size_t inner_size) {
144141 // The usable region includes the prev_ field of the next block.
145- return inner_size - sizeof (prev_) + BLOCK_OVERHEAD ;
142+ return inner_size - sizeof (prev_) + sizeof (Block) ;
146143 }
147144
148145 // / @returns The number of usable bytes inside the block were it to be
@@ -170,20 +167,20 @@ class Block {
170167 // / @returns The number of usable bytes inside a block with the given outer
171168 // / size if it remains free.
172169 LIBC_INLINE static size_t inner_size_free (size_t outer_size) {
173- return outer_size - BLOCK_OVERHEAD ;
170+ return outer_size - sizeof (Block) ;
174171 }
175172
176173 // / @returns A pointer to the usable space inside this block.
177174 // /
178175 // / Aligned to some multiple of max_align_t.
179176 LIBC_INLINE cpp::byte *usable_space () {
180- auto *s = reinterpret_cast <cpp::byte *>(this ) + BLOCK_OVERHEAD ;
177+ auto *s = reinterpret_cast <cpp::byte *>(this ) + sizeof (Block) ;
181178 LIBC_ASSERT (reinterpret_cast <uintptr_t >(s) % alignof (max_align_t ) == 0 &&
182179 " usable space must be aligned to a multiple of max_align_t" );
183180 return s;
184181 }
185182 LIBC_INLINE const cpp::byte *usable_space () const {
186- const auto *s = reinterpret_cast <const cpp::byte *>(this ) + BLOCK_OVERHEAD ;
183+ const auto *s = reinterpret_cast <const cpp::byte *>(this ) + sizeof (Block) ;
187184 LIBC_ASSERT (reinterpret_cast <uintptr_t >(s) % alignof (max_align_t ) == 0 &&
188185 " usable space must be aligned to a multiple of max_align_t" );
189186 return s;
@@ -246,7 +243,8 @@ class Block {
246243 LIBC_INLINE void mark_last () { next_ |= LAST_MASK; }
247244
248245 LIBC_INLINE Block (size_t outer_size) : next_(outer_size) {
249- LIBC_ASSERT (outer_size % ALIGNMENT == 0 && " block sizes must be aligned" );
246+ LIBC_ASSERT (outer_size % alignof (max_align_t ) == 0 &&
247+ " block sizes must be aligned" );
250248 LIBC_ASSERT (is_usable_space_aligned (alignof (max_align_t )) &&
251249 " usable space must be aligned to a multiple of max_align_t" );
252250 }
@@ -362,8 +360,8 @@ class Block {
362360 // / summarily considered used and has no next block.
363361};
364362
365- inline constexpr size_t Block::BLOCK_OVERHEAD =
366- align_up ( sizeof (Block), ALIGNMENT );
363+ static_assert ( alignof ( max_align_t ) >= 4 ,
364+ " at least 2 bits must be available in block sizes for flags " );
367365
368366LIBC_INLINE
369367optional<Block *> Block::init (ByteSpan region) {
0 commit comments