Commit Graph

1 Commits

Author SHA1 Message Date
c848a60696 Phase REFACTOR-3: Inline Pointer Macro Centralization (tiny_base_to_user_inline)
Centralize BASE ↔ USER pointer conversions into reusable, zero-cost macros.
Previously, pointer arithmetic (base + 1, ptr - 1) was scattered across
allocation/deallocation code with hardcoded offsets.

Changes:
- NEW: core/box/tiny_ptr_convert_box.h
  - tiny_base_to_user_inline(): BASE → USER (base + TINY_HEADER_OFFSET)
  - tiny_user_to_base_inline(): USER → BASE (user - TINY_HEADER_OFFSET)
  - TINY_HEADER_OFFSET: Centralized constant (currently 1)
  - Function variants: tiny_base_to_user(), tiny_user_to_base()

- Modified: core/front/malloc_tiny_fast.h
  - L181: return (uint8_t*)base + 1 → tiny_base_to_user_inline(base)
  - L299: void* base = (void*)((char*)ptr - 1) → tiny_user_to_base_inline(ptr)

Benefits:
- Self-documenting code (semantic intent is clear)
- Single source of truth for header offset
- Easier to extend (e.g., variable-length headers, alignment changes)
- Type-safe conversions (macro validates pointer types)
- Zero performance cost (inline macro, same compiled code)

Contract:
- Header stored at offset -1 from USER pointer
- Allocation: base → user (user = base + 1)
- Deallocation: user → base (base = user - 1)

No semantic changes - identical logic, just centralized.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-11 19:02:49 +09:00