From 3d39b4e3d6eb4c26bfbbc0f4b35fed5ca5ac3a2b Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Sun, 26 May 2024 13:17:54 +0200 Subject: [PATCH] Made the GC reclaim successful routines --- lib.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib.c b/lib.c index 538d4c7..772c3ef 100644 --- a/lib.c +++ b/lib.c @@ -1004,8 +1004,16 @@ void ink_gc(struct context* ctx) { } } - /* Start by marking the roots of the routines */ + /* Start by marking the roots of the routines, Clear the routines if possible */ for(i = 0; i < ctx->routines_top; ++i) { + if(ctx->routine[i].panic == INK_ROUTINE_SUCCESS) { + ctx->free(ctx->routine[i].stack); + ctx->free(ctx->routine[i].function_stack); + ctx->routine[i].panic = INK_ROUTINE_CAN_REUSE; + } + if(ctx->routine[i].panic == INK_ROUTINE_CAN_REUSE) { + continue; + } for(j = 0; j < ctx->routines[i].top; ++j) { v = ink_get_value_link(ctx, ctx->routines[i].stack[j]); if(v != NULL) ++v->uses;