From 8ac9aa9f90b608421098efb563a065f8787dbd6f Mon Sep 17 00:00:00 2001 From: Teddy Date: Thu, 15 Aug 2013 20:25:37 +0800 Subject: remove unnecessary std::set in gc --- gc.cpp | 10 ++++------ gc.h | 8 ++++++-- model.h | 3 +-- types.cpp | 14 +++++++------- types.h | 14 +++++++------- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/gc.cpp b/gc.cpp index c240192..0e4fc3d 100644 --- a/gc.cpp +++ b/gc.cpp @@ -110,7 +110,6 @@ EvalObj *GarbageCollector::attach(EvalObj *ptr) { } void GarbageCollector::cycle_resolve() { - EvalObjSet visited; Container **clptr = cyc_list; for (ObjEntry *i = joined->next; i != oe_null; i = i->next) { @@ -126,17 +125,16 @@ void GarbageCollector::cycle_resolve() { EvalObj **l = gcq, **r = l; for (Container **p = cyc_list; p < clptr; p++) (*p)->gc_decrement(); + for (Container **p = cyc_list; p < clptr; p++) - if ((*p)->gc_refs) - { + if ((*p)->gc_refs) // must not be recycled *r++ = *p; - visited.insert(*p); - } + for (; l != r; l++) { Container *p = static_cast(*l); p->keep = true; - p->gc_trigger(r, visited); + p->gc_trigger(r); } for (Container **p = cyc_list; p < clptr; p++) if (!(*p)->keep) diff --git a/gc.h b/gc.h index 9f1aca6..ad8ac6b 100644 --- a/gc.h +++ b/gc.h @@ -12,8 +12,12 @@ class GarbageCollector; #define GC_CYC_TRIGGER(ptr) \ do { \ - if ((ptr) && (ptr)->is_container() && !visited.count(ptr)) \ - visited.insert(*tail++ = (ptr)); \ + if ((ptr) && (ptr)->is_container() && \ + !(static_cast(ptr)->keep)) \ + { \ + static_cast(ptr)->keep = true; \ + *tail++ = (ptr); \ + } \ } while (0) #define GC_CYC_DEC(ptr) \ diff --git a/model.h b/model.h index 66c16f9..797631d 100644 --- a/model.h +++ b/model.h @@ -114,14 +114,13 @@ class ParseBracket : public FrameObj {/*{{{*/ };/*}}}*/ -typedef std::set EvalObjSet; class Container: public EvalObj {/*{{{*/ public: bool keep; size_t gc_refs; Container(int otype = 0, bool override = false); virtual void gc_decrement() = 0; - virtual void gc_trigger(EvalObj ** &tail, EvalObjSet &visited) = 0; + virtual void gc_trigger(EvalObj ** &tail) = 0; };/*}}}*/ #endif diff --git a/types.cpp b/types.cpp index 0cfe0be..aef780f 100644 --- a/types.cpp +++ b/types.cpp @@ -32,7 +32,7 @@ void Pair::gc_decrement() { GC_CYC_DEC(cdr); } -void Pair::gc_trigger(EvalObj ** &tail, EvalObjSet &visited) { +void Pair::gc_trigger(EvalObj ** &tail) { GC_CYC_TRIGGER(car); GC_CYC_TRIGGER(cdr); } @@ -53,7 +53,7 @@ OptObj::OptObj(int otype) : Container(otype | CLS_SIM_OBJ | CLS_OPT_OBJ, true) {} void OptObj::gc_decrement() {} -void OptObj::gc_trigger(EvalObj ** &tail, EvalObjSet &visited) {} +void OptObj::gc_trigger(EvalObj ** &tail) {} ProcObj::ProcObj(Pair *_body, Environment *_envt, EvalObj *_params) : OptObj(CLS_CONTAINER), body(_body), params(_params), envt(_envt) { @@ -138,7 +138,7 @@ void ProcObj::gc_decrement() { GC_CYC_DEC(envt); } -void ProcObj::gc_trigger(EvalObj ** &tail, EvalObjSet &visited) { +void ProcObj::gc_trigger(EvalObj ** &tail) { GC_CYC_TRIGGER(body); GC_CYC_TRIGGER(params); GC_CYC_TRIGGER(envt); @@ -260,7 +260,7 @@ void VecObj::gc_decrement() { GC_CYC_DEC(*it); } -void VecObj::gc_trigger(EvalObj ** &tail, EvalObjSet &visited) { +void VecObj::gc_trigger(EvalObj ** &tail) { for (EvalObjVec::iterator it = vec.begin(); it != vec.end(); it++) GC_CYC_TRIGGER(*it); @@ -333,7 +333,7 @@ void Environment::gc_decrement() { GC_CYC_DEC(it->second); } -void Environment::gc_trigger(EvalObj ** &tail, EvalObjSet &visited) { +void Environment::gc_trigger(EvalObj ** &tail) { GC_CYC_TRIGGER(prev_envt); for (Str2EvalObj::iterator it = binding.begin(); it != binding.end(); it++) @@ -412,7 +412,7 @@ void Continuation::gc_decrement() { GC_CYC_DEC(envt); } -void Continuation::gc_trigger(EvalObj ** &tail, EvalObjSet &visited) { +void Continuation::gc_trigger(EvalObj ** &tail) { GC_CYC_TRIGGER(prev_cont); GC_CYC_TRIGGER(envt); } @@ -502,7 +502,7 @@ void PromObj::gc_decrement() { GC_CYC_DEC(mem); } -void PromObj::gc_trigger(EvalObj ** &tail, EvalObjSet &visited) { +void PromObj::gc_trigger(EvalObj ** &tail) { GC_CYC_TRIGGER(entry); GC_CYC_TRIGGER(mem); } diff --git a/types.h b/types.h index 345e17b..3b948e4 100644 --- a/types.h +++ b/types.h @@ -54,7 +54,7 @@ class Pair : public Container {/*{{{*/ ~Pair(); ReprCons *get_repr_cons(); void gc_decrement(); - void gc_trigger(EvalObj ** &tail, EvalObjSet &visited); + void gc_trigger(EvalObj ** &tail); };/*}}}*/ /** @class EmptyList @@ -143,7 +143,7 @@ class OptObj: public Container {/*{{{*/ virtual Pair *call(Pair *args, Environment * &envt, Continuation * &cont, EvalObj ** &top_ptr, Pair *pc) = 0; virtual void gc_decrement(); - virtual void gc_trigger(EvalObj ** &tail, EvalObjSet &visited); + virtual void gc_trigger(EvalObj ** &tail); };/*}}}*/ @@ -167,7 +167,7 @@ class ProcObj: public OptObj {/*{{{*/ ReprCons *get_repr_cons(); void gc_decrement(); - void gc_trigger(EvalObj ** &tail, EvalObjSet &visited); + void gc_trigger(EvalObj ** &tail); };/*}}}*/ /** @class SpecialOptObj @@ -309,7 +309,7 @@ class VecObj: public Container {/*{{{*/ ReprCons *get_repr_cons(); void gc_decrement(); - void gc_trigger(EvalObj ** &tail, EvalObjSet &visited); + void gc_trigger(EvalObj ** &tail); };/*}}}*/ /** @@ -329,7 +329,7 @@ class PromObj: public Container {/*{{{*/ ReprCons *get_repr_cons(); void gc_decrement(); - void gc_trigger(EvalObj ** &tail, EvalObjSet &visited); + void gc_trigger(EvalObj ** &tail); };/*}}}*/ /** @class Environment @@ -361,7 +361,7 @@ class Environment : public Container{/*{{{*/ Environment *get_prev(); void gc_decrement(); - void gc_trigger(EvalObj ** &tail, EvalObjSet &visited); + void gc_trigger(EvalObj ** &tail); };/*}}}*/ /** @class Continuation @@ -385,7 +385,7 @@ class Continuation : public Container {/*{{{*/ ReprCons *get_repr_cons(); void gc_decrement(); - void gc_trigger(EvalObj ** &tail, EvalObjSet &visited); + void gc_trigger(EvalObj ** &tail); };/*}}}*/ /** @class InexactNumObj -- cgit v1.2.3-70-g09d2