@@ -109,9 +109,6 @@ class Block {
109
109
static constexpr size_t SIZE_MASK = ~(PREV_FREE_MASK | LAST_MASK);
110
110
111
111
public:
112
- static constexpr size_t ALIGNMENT = cpp::max(alignof (max_align_t ), size_t {4 });
113
- static const size_t BLOCK_OVERHEAD;
114
-
115
112
// No copy or move.
116
113
Block (const Block &other) = delete ;
117
114
Block &operator =(const Block &other) = delete ;
@@ -130,19 +127,19 @@ class Block {
130
127
// / pointer will return a non-null pointer.
131
128
LIBC_INLINE static Block *from_usable_space (void *usable_space) {
132
129
auto *bytes = reinterpret_cast <cpp::byte *>(usable_space);
133
- return reinterpret_cast <Block *>(bytes - BLOCK_OVERHEAD );
130
+ return reinterpret_cast <Block *>(bytes - sizeof (Block) );
134
131
}
135
132
LIBC_INLINE static const Block *from_usable_space (const void *usable_space) {
136
133
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) );
138
135
}
139
136
140
137
// / @returns The total size of the block in bytes, including the header.
141
138
LIBC_INLINE size_t outer_size () const { return next_ & SIZE_MASK; }
142
139
143
140
LIBC_INLINE static size_t outer_size (size_t inner_size) {
144
141
// 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) ;
146
143
}
147
144
148
145
// / @returns The number of usable bytes inside the block were it to be
@@ -170,20 +167,20 @@ class Block {
170
167
// / @returns The number of usable bytes inside a block with the given outer
171
168
// / size if it remains free.
172
169
LIBC_INLINE static size_t inner_size_free (size_t outer_size) {
173
- return outer_size - BLOCK_OVERHEAD ;
170
+ return outer_size - sizeof (Block) ;
174
171
}
175
172
176
173
// / @returns A pointer to the usable space inside this block.
177
174
// /
178
175
// / Aligned to some multiple of max_align_t.
179
176
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) ;
181
178
LIBC_ASSERT (reinterpret_cast <uintptr_t >(s) % alignof (max_align_t ) == 0 &&
182
179
" usable space must be aligned to a multiple of max_align_t" );
183
180
return s;
184
181
}
185
182
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) ;
187
184
LIBC_ASSERT (reinterpret_cast <uintptr_t >(s) % alignof (max_align_t ) == 0 &&
188
185
" usable space must be aligned to a multiple of max_align_t" );
189
186
return s;
@@ -246,7 +243,8 @@ class Block {
246
243
LIBC_INLINE void mark_last () { next_ |= LAST_MASK; }
247
244
248
245
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" );
250
248
LIBC_ASSERT (is_usable_space_aligned (alignof (max_align_t )) &&
251
249
" usable space must be aligned to a multiple of max_align_t" );
252
250
}
@@ -362,8 +360,8 @@ class Block {
362
360
// / summarily considered used and has no next block.
363
361
};
364
362
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 " );
367
365
368
366
LIBC_INLINE
369
367
optional<Block *> Block::init (ByteSpan region) {
0 commit comments