diff options
author | Attila Molnar <attilamolnar@hush.com> | 2014-03-28 12:20:39 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2014-03-28 12:20:39 +0100 |
commit | 025aa693fd47228d101062248ff7b71ec9638a71 (patch) | |
tree | 5d05594382e4329580a2aafbff0fdb96cb51f799 | |
parent | 8f31b0cf2a753cd7b6af8fd1dc730d0693ebeb90 (diff) |
Convert the global list of dynamic reference pointers to an intrusively linked list
-rw-r--r-- | include/dynref.h | 2 | ||||
-rw-r--r-- | src/modules.cpp | 28 |
2 files changed, 10 insertions, 20 deletions
diff --git a/include/dynref.h b/include/dynref.h index 1d05b35a0..02474b67e 100644 --- a/include/dynref.h +++ b/include/dynref.h @@ -22,7 +22,7 @@ #include "base.h" -class CoreExport dynamic_reference_base : public interfacebase +class CoreExport dynamic_reference_base : public interfacebase, public intrusive_list_node<dynamic_reference_base> { private: std::string name; diff --git a/src/modules.cpp b/src/modules.cpp index a4b5ae4bc..c27147820 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -36,7 +36,7 @@ #include <dirent.h> #endif -static std::vector<dynamic_reference_base*>* dynrefs = NULL; +static intrusive_list<dynamic_reference_base>* dynrefs = NULL; static bool dynref_init_complete = false; void dynamic_reference_base::reset_all() @@ -44,8 +44,8 @@ void dynamic_reference_base::reset_all() dynref_init_complete = true; if (!dynrefs) return; - for(unsigned int i = 0; i < dynrefs->size(); i++) - (*dynrefs)[i]->resolve(); + for (intrusive_list<dynamic_reference_base>::iterator i = dynrefs->begin(); i != dynrefs->end(); ++i) + (*i)->resolve(); } // Version is a simple class for holding a modules version number @@ -676,29 +676,19 @@ dynamic_reference_base::dynamic_reference_base(Module* Creator, const std::strin : name(Name), value(NULL), creator(Creator) { if (!dynrefs) - dynrefs = new std::vector<dynamic_reference_base*>; - dynrefs->push_back(this); + dynrefs = new intrusive_list<dynamic_reference_base>; + dynrefs->push_front(this); if (dynref_init_complete) resolve(); } dynamic_reference_base::~dynamic_reference_base() { - for(unsigned int i = 0; i < dynrefs->size(); i++) + dynrefs->erase(this); + if (dynrefs->empty()) { - if (dynrefs->at(i) == this) - { - unsigned int last = dynrefs->size() - 1; - if (i != last) - dynrefs->at(i) = dynrefs->at(last); - dynrefs->erase(dynrefs->begin() + last); - if (dynrefs->empty()) - { - delete dynrefs; - dynrefs = NULL; - } - return; - } + delete dynrefs; + dynrefs = NULL; } } |