diff --git a/src/gc.c b/src/gc.c index e1f0ce0b9..2110e14eb 100644 --- a/src/gc.c +++ b/src/gc.c @@ -371,8 +371,23 @@ mrb_gc_destroy(mrb_state *mrb, mrb_gc *gc) #endif } +#ifdef MRB_GC_FIXED_ARENA +#define gc_arena_keep(mrb, gc) /* empty */ +#else static void gc_arena_keep(mrb_state *mrb, mrb_gc *gc) +{ + if (gc->arena_idx >= gc->arena_capa) { + /* extend arena */ + int newcapa = gc->arena_capa * 3 / 2; + gc->arena = (struct RBasic**)mrb_realloc(mrb, gc->arena, sizeof(struct RBasic*)*newcapa); + gc->arena_capa = newcapa; + } +} +#endif + +static inline void +gc_protect(mrb_state *mrb, mrb_gc *gc, struct RBasic *p) { #ifdef MRB_GC_FIXED_ARENA if (gc->arena_idx >= MRB_GC_ARENA_SIZE) { @@ -380,24 +395,8 @@ gc_arena_keep(mrb_state *mrb, mrb_gc *gc) gc->arena_idx = MRB_GC_ARENA_SIZE - 4; /* force room in arena */ mrb_exc_raise(mrb, mrb_obj_value(mrb->arena_err)); } -#else - if (gc->arena_idx >= gc->arena_capa) { - /* extend arena */ - int newcapa = gc->arena_capa * 3 / 2; - gc->arena = (struct RBasic**)mrb_realloc(mrb, gc->arena, sizeof(struct RBasic*)*newcapa); - gc->arena_capa = newcapa; - } -#endif -} - -static inline void -gc_protect(mrb_state *mrb, mrb_gc *gc, struct RBasic *p) -{ -#ifdef MRB_GC_FIXED_ARENA - mrb_assert(gc->arena_idx < MRB_GC_ARENA_SIZE); -#else - mrb_assert(gc->arena_idx < gc->arena_capa); #endif + gc_arena_keep(mrb, gc); gc->arena[gc->arena_idx++] = p; } @@ -408,7 +407,6 @@ mrb_gc_protect(mrb_state *mrb, mrb_value obj) if (mrb_immediate_p(obj)) return; struct RBasic *p = mrb_basic_ptr(obj); if (is_red(p)) return; - gc_arena_keep(mrb, &mrb->gc); gc_protect(mrb, &mrb->gc, p); }