From addbfae58d8afceb06d92f6ef1cdfed89c07518b Mon Sep 17 00:00:00 2001 From: Teddy Date: Wed, 14 Aug 2013 23:28:20 +0800 Subject: significant improvement on gc efficiency --- model.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'model.cpp') diff --git a/model.cpp b/model.cpp index 64a3c96..32c79d0 100644 --- a/model.cpp +++ b/model.cpp @@ -4,9 +4,11 @@ #include "exc.h" #include "consts.h" #include "types.h" +#include "gc.h" const int REPR_STACK_SIZE = 262144; extern EmptyList *empty_list; +extern GarbageCollector gc; static EvalObjAddrHash hash; static ReprCons *repr_stack[REPR_STACK_SIZE]; @@ -21,7 +23,18 @@ bool FrameObj::is_parse_bracket() { return ftype & CLS_PAR_BRA; } -EvalObj::EvalObj(int _otype) : FrameObj(CLS_EVAL_OBJ), otype(_otype) {} +bool EvalObj::gc_dec() { return --gc_cnt == 0; } +void EvalObj::gc_inc() { gc_cnt++; } +size_t EvalObj::gc_get_cnt() { return gc_cnt; } + +EvalObj::EvalObj(int _otype) : + FrameObj(CLS_EVAL_OBJ), gc_cnt(0), otype(_otype) { + gc.join(this); +} + +EvalObj::~EvalObj() { + gc.quit(this); +} bool EvalObj::is_container() { return otype & CLS_CONTAINER; -- cgit v1.2.3