diff options
author | Adam <Adam@drink-coca-cola.info> | 2010-05-14 20:35:38 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-06-18 21:01:53 -0400 |
commit | f049124905bd9f53439293e873003cb027a17b91 (patch) | |
tree | 352ed9251fd47055dd770aa2d5eabb20247e4b43 /src/module.cpp | |
parent | 81a45520a773732c9f46785f27aa1956150775d7 (diff) |
Rewrote the hashing system to use std::tr1::unordered_map
Diffstat (limited to 'src/module.cpp')
-rw-r--r-- | src/module.cpp | 151 |
1 files changed, 69 insertions, 82 deletions
diff --git a/src/module.cpp b/src/module.cpp index 4582ac069..b30e2b6a7 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -24,31 +24,12 @@ Module::Module(const std::string &mname, const std::string &creator) this->lang[i].argc = 0; } - int index = 0; - ModuleHash *current = NULL; - ModuleHash *newHash = NULL; - ModuleHash *lastHash = NULL; - - index = CMD_HASH(this->name); - - for (current = MODULE_HASH[index]; current; current = current->next) { - if (this->name ==current->name) - throw CoreException("Module already exists!"); - lastHash = current; - } - - if (!(newHash = new ModuleHash)) { - fatal("Out of memory"); - } + if (FindModule(this->name)) + throw CoreException("Module already exists!"); + this->created = time(NULL); - newHash->next = NULL; - newHash->name = sstrdup(this->name.c_str()); - newHash->m = this; - - if (lastHash == NULL) - MODULE_HASH[index] = newHash; - else - lastHash->next = newHash; + + Modules.push_back(this); } Module::~Module() @@ -60,85 +41,91 @@ Module::~Module() remove(this->filename.c_str()); - int idx; - CommandHash *current = NULL; - - Command *c; - /* Clear any active callbacks this module has */ ModuleManager::ClearCallBacks(this); /** * ok, im going to walk every hash looking for commands we own, now, not exactly elegant or efficiant :) **/ - for (idx = 0; idx < MAX_CMD_HASH; idx++) { - for (current = HS_cmdTable[idx]; current; current = current->next) { - for (c = current->c; c; c = c->next) { - if ((c->mod_name) && (strcmp(c->mod_name, this->name.c_str()) == 0)) { - this->DelCommand(HOSTSERV, c->name.c_str()); - } - } + if (HostServ) + { + for (std::map<ci::string, Command *>::iterator it = HostServ->Commands.begin(); it != HostServ->Commands.end();) + { + Command *c = it->second; + ++it; + + if (c->module == this) + this->DelCommand(HostServ, c); } + } + + if (BotServ) + { + for (std::map<ci::string, Command *>::iterator it = BotServ->Commands.begin(); it != BotServ->Commands.end();) + { + Command *c = it->second; + ++it; - for (current = BS_cmdTable[idx]; current; current = current->next) { - for (c = current->c; c; c = c->next) { - if ((c->mod_name) && (strcmp(c->mod_name, this->name.c_str()) == 0)) { - this->DelCommand(BOTSERV, c->name.c_str()); - } - } + if (c->module == this) + this->DelCommand(BotServ, c); } + } + + if (MemoServ) + { + for (std::map<ci::string, Command *>::iterator it = MemoServ->Commands.begin(); it != MemoServ->Commands.end();) + { + Command *c = it->second; + ++it; - for (current = MS_cmdTable[idx]; current; current = current->next) { - for (c = current->c; c; c = c->next) { - if ((c->mod_name) && (strcmp(c->mod_name, this->name.c_str()) == 0)) { - this->DelCommand(MEMOSERV, c->name.c_str()); - } - } + if (c->module == this) + this->DelCommand(MemoServ, c); } + } + + if (NickServ) + { + for (std::map<ci::string, Command *>::iterator it = NickServ->Commands.begin(); it != NickServ->Commands.end();) + { + Command *c = it->second; + ++it; - for (current = NS_cmdTable[idx]; current; current = current->next) { - for (c = current->c; c; c = c->next) { - if ((c->mod_name) && (strcmp(c->mod_name, this->name.c_str()) == 0)) { - this->DelCommand(NICKSERV, c->name.c_str()); - } - } + if (c->module == this) + this->DelCommand(NickServ, c); } + } + + if (ChanServ) + { + for (std::map<ci::string, Command *>::iterator it = ChanServ->Commands.begin(); it != ChanServ->Commands.end();) + { + Command *c = it->second; + ++it; - for (current = CS_cmdTable[idx]; current; current = current->next) { - for (c = current->c; c; c = c->next) { - if ((c->mod_name) && (strcmp(c->mod_name, this->name.c_str()) == 0)) { - this->DelCommand(CHANSERV, c->name.c_str()); - } - } + if (c->module == this) + this->DelCommand(ChanServ, c); } + } - for (current = OS_cmdTable[idx]; current; current = current->next) { - for (c = current->c; c; c = c->next) { - if ((c->mod_name) && (stricmp(c->mod_name, this->name.c_str()) == 0)) { - this->DelCommand(OPERSERV, c->name.c_str()); - } - } + if (OperServ) + { + for (std::map<ci::string, Command *>::iterator it = OperServ->Commands.begin(); it != OperServ->Commands.end();) + { + Command *c = it->second; + ++it; + + if (c->module == this) + this->DelCommand(OperServ, c); } } - int index = 0; - ModuleHash *lastHash = NULL; - ModuleHash *mhash = NULL; - - index = CMD_HASH(this->name); - - for (mhash = MODULE_HASH[index]; mhash; mhash = mhash->next) { - if (this->name == mhash->name) { - if (!lastHash) { - MODULE_HASH[index] = mhash->next; - } else { - lastHash->next = mhash->next; - } - delete [] mhash->name; - delete mhash; + for (std::deque<Module *>::iterator it = Modules.begin(); it != Modules.end(); ++it) + { + if (*it == this) + { + Modules.erase(it); break; } - lastHash = mhash; } } |