summaryrefslogtreecommitdiff
path: root/src/modules.cpp
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2014-03-28 12:20:39 +0100
committerAttila Molnar <attilamolnar@hush.com>2014-03-28 12:20:39 +0100
commit025aa693fd47228d101062248ff7b71ec9638a71 (patch)
tree5d05594382e4329580a2aafbff0fdb96cb51f799 /src/modules.cpp
parent8f31b0cf2a753cd7b6af8fd1dc730d0693ebeb90 (diff)
Convert the global list of dynamic reference pointers to an intrusively linked list
Diffstat (limited to 'src/modules.cpp')
-rw-r--r--src/modules.cpp28
1 files changed, 9 insertions, 19 deletions
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;
}
}