@@ -174,32 +174,16 @@ class Block {
174
174
return inner_size - sizeof (prev_) + BLOCK_OVERHEAD;
175
175
}
176
176
177
- // / @returns The number of usable bytes inside the block were it to be
178
- // / allocated.
177
+ // / @returns The number of usable bytes inside the block.
179
178
size_t inner_size () const {
180
179
if (!next ())
181
180
return 0 ;
182
181
return inner_size (outer_size ());
183
182
}
184
183
185
- // / @returns The number of usable bytes inside a block with the given outer
186
- // / size were it to be allocated.
187
184
static size_t inner_size (size_t outer_size) {
188
185
// The usable region includes the prev_ field of the next block.
189
- return inner_size_free (outer_size) + sizeof (prev_);
190
- }
191
-
192
- // / @returns The number of usable bytes inside the block if it remains free.
193
- size_t inner_size_free () const {
194
- if (!next ())
195
- return 0 ;
196
- return inner_size_free (outer_size ());
197
- }
198
-
199
- // / @returns The number of usable bytes inside a block with the given outer
200
- // / size if it remains free.
201
- static size_t inner_size_free (size_t outer_size) {
202
- return outer_size - BLOCK_OVERHEAD;
186
+ return outer_size - BLOCK_OVERHEAD + sizeof (prev_);
203
187
}
204
188
205
189
// / @returns A pointer to the usable space inside this block.
@@ -217,11 +201,14 @@ class Block {
217
201
218
202
// / Attempts to split this block.
219
203
// /
220
- // / If successful, the block will have an inner size of at least
221
- // / `new_inner_size`, rounded to ensure that the split point is on an
222
- // / ALIGNMENT boundary. The remaining space will be returned as a new block.
223
- // / Note that the prev_ field of the next block counts as part of the inner
224
- // / size of the returnd block.
204
+ // / If successful, the block will have an inner size of `new_inner_size`,
205
+ // / rounded to ensure that the split point is on an ALIGNMENT boundary. The
206
+ // / remaining space will be returned as a new block. Note that the prev_ field
207
+ // / of the next block counts as part of the inner size of the returnd block.
208
+ // /
209
+ // / This method may fail if the remaining space is too small to hold a new
210
+ // / block. If this method fails for any reason, the original block is
211
+ // / unmodified.
225
212
optional<Block *> split (size_t new_inner_size);
226
213
227
214
// / Merges this block with the one that comes after it.
@@ -455,7 +442,7 @@ Block<OffsetType, kAlign>::split(size_t new_inner_size) {
455
442
// The prev_ field of the next block is always available, so there is a
456
443
// minimum size to a block created through splitting.
457
444
if (new_inner_size < sizeof (prev_))
458
- new_inner_size = sizeof (prev_) ;
445
+ return {} ;
459
446
460
447
size_t old_inner_size = inner_size ();
461
448
new_inner_size =
0 commit comments