diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-10-21 23:46:13 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-10-21 23:46:13 +0000 |
commit | d8f98565a8617658f610bc94a5d87266930beee4 (patch) | |
tree | 365a153c59bc8b521b094c27f25b484a69e5154b /src/modules.cpp | |
parent | 984cc96a1f832abf9b5fcfddcd8260c5b12bd2a9 (diff) |
Use ConfigTagList as a faster access method for access to configuration
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11948 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules.cpp')
-rw-r--r-- | src/modules.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/modules.cpp b/src/modules.cpp index a4b9e05fa..f70c45bf2 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -588,11 +588,10 @@ void ModuleManager::LoadAll() printf("\n"); } - for(int count = 0;; count++) + ConfigTagList tags = ServerInstance->Config->ConfTags("module"); + for(ConfigIter i = tags.first; i != tags.second; ++i) { - ConfigTag* tag = ServerInstance->Config->ConfValue("module", count); - if (!tag) - break; + ConfigTag* tag = i->second; std::string name = tag->getString("name"); printf_c("[\033[1;32m*\033[0m] Loading module:\t\033[1;32m%s\033[0m\n",name.c_str()); @@ -825,12 +824,23 @@ ConfigReader::~ConfigReader() { } +static ConfigTag* SlowGetTag(const std::string &tag, int index) +{ + ConfigTagList tags = ServerInstance->Config->ConfTags(tag); + while (tags.first != tags.second) + { + if (!index) + return tags.first->second; + tags.first++; + index--; + } + return NULL; +} std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds) { - /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */ std::string result = default_value; - if (!ServerInstance->Config->ConfValue(tag, index)->readString(name, result, allow_linefeeds)) + if (!SlowGetTag(tag, index)->readString(name, result, allow_linefeeds)) { this->error = CONF_VALUE_NOT_FOUND; } @@ -845,7 +855,7 @@ std::string ConfigReader::ReadValue(const std::string &tag, const std::string &n bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, const std::string &default_value, int index) { bool def = (default_value == "yes"); - return ServerInstance->Config->ConfValue(tag, index)->getBool(name, def); + return SlowGetTag(tag, index)->getBool(name, def); } bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index) @@ -857,7 +867,7 @@ bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool need_positive) { int v = atoi(default_value.c_str()); - int result = ServerInstance->Config->ConfValue(tag, index)->getInt(name, v); + int result = SlowGetTag(tag, index)->getInt(name, v); if ((need_positive) && (result < 0)) { @@ -885,7 +895,7 @@ int ConfigReader::Enumerate(const std::string &tag) ServerInstance->Logs->Log("MODULE", DEBUG, "Module is using ConfigReader::Enumerate on %s; this is slow!", tag.c_str()); int i=0; - while (ServerInstance->Config->ConfValue(tag, i)) i++; + while (SlowGetTag(tag, i)) i++; return i; } |