Phase REFACTOR-2: Legacy Fallback Logic Unification
Consolidate duplicated legacy free logic into a single reusable function. Previously, hak_tiny_free_legacy_inline() and hak_tiny_free_legacy_impl() contained identical implementations in malloc_tiny_fast.h and tiny_c6_ultra_free_box.c. Changes: - NEW: core/box/tiny_legacy_fallback_box.h - tiny_legacy_fallback_free_base(): Unified legacy free implementation - Encapsulates: Unified Cache push + per-class stats + final fallback - Contract: BASE pointer input (already extracted from USER ptr) - Modified: core/front/malloc_tiny_fast.h - Removed: hak_tiny_free_legacy_inline() (lines 96-111) - Replaced call: hak_tiny_free_legacy_inline → tiny_legacy_fallback_free_base - Modified: core/box/tiny_c6_ultra_free_box.c - Removed: hak_tiny_free_legacy_impl() (lines 17-39) - Replaced call: hak_tiny_free_legacy_impl → tiny_legacy_fallback_free_base Benefits: - Single source of truth (DRY principle) - Easier to maintain and test - Consistent behavior across all free paths - No performance impact (always_inline preserved) 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>
This commit is contained in:
@ -48,6 +48,7 @@
|
||||
#include "../box/tiny_c7_ultra_box.h" // C7 ULTRA stub (UF-1, delegates to v3)
|
||||
#include "../box/tiny_c6_ultra_free_box.h" // Phase 4-2: C6 ULTRA-free (free-only, C6-only)
|
||||
#include "../box/tiny_ultra_classes_box.h" // Phase REFACTOR-1: Named constants for C6/C7
|
||||
#include "../box/tiny_legacy_fallback_box.h" // Phase REFACTOR-2: Legacy fallback logic unification
|
||||
#include "../box/tiny_front_v3_env_box.h" // Tiny front v3 snapshot gate
|
||||
#include "../box/tiny_heap_env_box.h" // ENV gate for TinyHeap front (A/B)
|
||||
#include "../box/tiny_route_env_box.h" // Route snapshot (Heap vs Legacy)
|
||||
@ -83,33 +84,11 @@ static inline int front_gate_unified_enabled(void) {
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Phase 4-2: Legacy free helper (shared implementation in tiny_c6_ultra_free_box.c)
|
||||
// Phase REFACTOR-2: Legacy free helper (unified in tiny_legacy_fallback_box.h)
|
||||
// ============================================================================
|
||||
|
||||
// Helper function to perform legacy free (used in both regular path and C6 ULTRA fallback)
|
||||
__attribute__((always_inline))
|
||||
static inline void hak_tiny_free_legacy_inline(void* base, uint32_t class_idx) {
|
||||
const TinyFrontV3Snapshot* front_snap =
|
||||
__builtin_expect(tiny_front_v3_enabled(), 0) ? tiny_front_v3_snapshot_get() : NULL;
|
||||
|
||||
// Legacy fallback - Unified Cache push
|
||||
if (!front_snap || front_snap->unified_cache_on) {
|
||||
if (unified_cache_push(class_idx, HAK_BASE_FROM_RAW(base))) {
|
||||
FREE_PATH_STAT_INC(legacy_fallback);
|
||||
|
||||
// Phase 4-1: Legacy per-class breakdown
|
||||
if (__builtin_expect(free_path_stats_enabled(), 0)) {
|
||||
if (class_idx < 8) {
|
||||
g_free_path_stats.legacy_by_class[class_idx]++;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Final fallback
|
||||
tiny_hot_free_fast(class_idx, base);
|
||||
}
|
||||
// Legacy free handling is encapsulated in tiny_legacy_fallback_box.h
|
||||
// (Removed inline implementation to avoid duplication)
|
||||
|
||||
// ============================================================================
|
||||
// Phase 4-Step2: malloc_tiny_fast() - Hot/Cold Path Box (ACTIVE)
|
||||
@ -507,8 +486,8 @@ static inline int free_tiny_fast(void* ptr) {
|
||||
}
|
||||
#endif
|
||||
|
||||
// Phase 4-2: Legacy fallback (use inline helper)
|
||||
hak_tiny_free_legacy_inline(base, class_idx);
|
||||
// Phase REFACTOR-2: Legacy fallback (use unified helper)
|
||||
tiny_legacy_fallback_free_base(base, class_idx);
|
||||
return 1;
|
||||
#else
|
||||
// No header mode - fall back to normal free
|
||||
|
||||
Reference in New Issue
Block a user