diff options
author | Teddy <[email protected]> | 2013-08-15 20:25:37 +0800 |
---|---|---|
committer | Teddy <[email protected]> | 2013-08-15 20:25:37 +0800 |
commit | 8ac9aa9f90b608421098efb563a065f8787dbd6f (patch) | |
tree | 3bf018777a3c49ff7138294fdff5d6bd3325c69d | |
parent | 9b1d0e016822509e5d3ea7bdc6341b4533b42080 (diff) |
remove unnecessary std::set in gcgc_imp
-rw-r--r-- | gc.cpp | 10 | ||||
-rw-r--r-- | gc.h | 8 | ||||
-rw-r--r-- | model.h | 3 | ||||
-rw-r--r-- | types.cpp | 14 | ||||
-rw-r--r-- | types.h | 14 |
5 files changed, 25 insertions, 24 deletions
@@ -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<Container*>(*l); p->keep = true; - p->gc_trigger(r, visited); + p->gc_trigger(r); } for (Container **p = cyc_list; p < clptr; p++) if (!(*p)->keep) @@ -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<Container*>(ptr)->keep)) \ + { \ + static_cast<Container*>(ptr)->keep = true; \ + *tail++ = (ptr); \ + } \ } while (0) #define GC_CYC_DEC(ptr) \ @@ -114,14 +114,13 @@ class ParseBracket : public FrameObj {/*{{{*/ };/*}}}*/ -typedef std::set<EvalObj*> 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 @@ -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); } @@ -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 |