[libc-commits] [libc] [libc][malloc] Reduce block overhead by 4 bytes plus alignment effects (PR #99945)

via libc-commits libc-commits at lists.llvm.org
Tue Jul 23 11:50:32 PDT 2024


================
@@ -338,32 +323,26 @@ class Block {
   /// ensure the split will succeed.
   static Block *split_impl(Block *&block, size_t new_inner_size);
 
-  /// Offset (in increments of the minimum alignment) from this block to the
-  /// previous block. 0 if this is the first block.
+  /// Offset from this block to the previous block. 0 if this is the first
+  /// block.
   offset_type prev_ = 0;
 
-  /// Offset (in increments of the minimum alignment) from this block to the
-  /// next block. Valid even if this is the last block, since it equals the
-  /// size of the block.
+  /// Offset from this block to the next block. Valid even if this is the last
+  /// block, since it equals the size of the block.
   offset_type next_ = 0;
----------------
PiJoules wrote:

Since `next_` now encodes the old `info_` struct, do you think it would be more readable to use bitfields rather than depend on masks? Something like

```
    struct {
        offset_type next : sizeof(offset_type) * CHAR_BIT - 2;
        unsigned int used : 1;
        unsigned int last : 1;
    } info_;

size_t outer_size() const { return info_.next; }
void clear_last() { info_.last_ = 0; }
```

Other than this, LGTM

https://github.com/llvm/llvm-project/pull/99945


More information about the libc-commits mailing list