]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Store config values in a map instead of a unique vector of pairs.
authorPeter Powell <petpow@saberuk.com>
Thu, 8 Dec 2016 01:57:47 +0000 (01:57 +0000)
committerPeter Powell <petpow@saberuk.com>
Thu, 8 Dec 2016 02:01:40 +0000 (02:01 +0000)
include/configreader.h
include/typedefs.h
src/configparser.cpp
src/configreader.cpp
src/modules/m_httpd_config.cpp

index 005d4a37db8cdd4d7c5c5f0ebe385107465186c6..4d70d8510ac25660258f2d4092da6d66fd69b0ab 100644 (file)
@@ -35,7 +35,7 @@
 /** Structure representing a single \<tag> in config */
 class CoreExport ConfigTag : public refcountbase
 {
-       std::vector<KeyVal> items;
+       ConfigItems items;
  public:
        const std::string tag;
        const std::string src_name;
@@ -80,10 +80,10 @@ class CoreExport ConfigTag : public refcountbase
 
        std::string getTagLocation();
 
-       inline const std::vector<KeyVal>& getItems() const { return items; }
+       inline const ConfigItems& getItems() const { return items; }
 
-       /** Create a new ConfigTag, giving access to the private KeyVal item list */
-       static ConfigTag* create(const std::string& Tag, const std::string& file, int line, std::vector<KeyVal>*& Items);
+       /** Create a new ConfigTag, giving access to the private ConfigItems item list */
+       static ConfigTag* create(const std::string& Tag, const std::string& file, int line, ConfigItems*& Items);
  private:
        ConfigTag(const std::string& Tag, const std::string& file, int line);
 };
index 879ef062741453846fcfc3ce794628327375ee97..d7bfadc60a99eaa1252c74abf1793c455ac4a5cc 100644 (file)
@@ -66,9 +66,9 @@ typedef std::vector<Membership*> IncludeChanList;
  */
 typedef std::vector<std::string> file_cache;
 
-/** A configuration key and value pair
+/** A mapping of configuration keys to their assigned values.
  */
-typedef std::pair<std::string, std::string> KeyVal;
+typedef insp::flat_map<std::string, std::string> ConfigItems;
 
 /** The entire configuration
  */
index 8bf9aaec297fd5cec25bd5de717395748638c3b8..7c03fe58a1ad4869c6fc8acd8704f8e7a0cf5da1 100644 (file)
@@ -91,7 +91,7 @@ struct Parser
                unget(ch);
        }
 
-       bool kv(std::vector<KeyVal>* items, std::set<std::string>& seen)
+       bool kv(ConfigItems* items)
        {
                std::string key;
                nextword(key);
@@ -177,10 +177,10 @@ struct Parser
                                value.push_back(ch);
                }
 
-               if (!seen.insert(key).second)
+               if (items->find(key) != items->end())
                        throw CoreException("Duplicate key '" + key + "' found");
 
-               items->push_back(KeyVal(key, value));
+               (*items)[key] = value;
                return true;
        }
 
@@ -199,11 +199,10 @@ struct Parser
                if (name.empty())
                        throw CoreException("Empty tag name");
 
-               std::vector<KeyVal>* items;
-               std::set<std::string> seen;
+               ConfigItems* items;
                tag = ConfigTag::create(name, current.filename, current.line, items);
 
-               while (kv(items, seen))
+               while (kv(items))
                {
                        // Do nothing here (silences a GCC warning).
                }
@@ -220,14 +219,14 @@ struct Parser
                }
                else if (name == "files")
                {
-                       for(std::vector<KeyVal>::iterator i = items->begin(); i != items->end(); i++)
+                       for(ConfigItems::iterator i = items->begin(); i != items->end(); i++)
                        {
                                stack.DoReadFile(i->first, i->second, flags, false);
                        }
                }
                else if (name == "execfiles")
                {
-                       for(std::vector<KeyVal>::iterator i = items->begin(); i != items->end(); i++)
+                       for(ConfigItems::iterator i = items->begin(); i != items->end(); i++)
                        {
                                stack.DoReadFile(i->first, i->second, flags, true);
                        }
@@ -385,7 +384,7 @@ bool ParseStack::ParseFile(const std::string& path, int flags, const std::string
 
 bool ConfigTag::readString(const std::string& key, std::string& value, bool allow_lf)
 {
-       for(std::vector<KeyVal>::iterator j = items.begin(); j != items.end(); ++j)
+       for(ConfigItems::iterator j = items.begin(); j != items.end(); ++j)
        {
                if(j->first != key)
                        continue;
@@ -488,7 +487,7 @@ std::string ConfigTag::getTagLocation()
        return src_name + ":" + ConvToStr(src_line);
 }
 
-ConfigTag* ConfigTag::create(const std::string& Tag, const std::string& file, int line, std::vector<KeyVal>*& Items)
+ConfigTag* ConfigTag::create(const std::string& Tag, const std::string& file, int line, ConfigItems*& Items)
 {
        ConfigTag* rv = new ConfigTag(Tag, file, line);
        Items = &rv->items;
index 9d327532b27f1c35f6fc45a7210b6622501d9ca0..8263b8737c6156a1eab556a3e55f8be30d69ddf7 100644 (file)
@@ -46,7 +46,7 @@ ServerLimits::ServerLimits(ConfigTag* tag)
 
 static ConfigTag* CreateEmptyTag()
 {
-       std::vector<KeyVal>* items;
+       ConfigItems* items;
        return ConfigTag::create("empty", "<auto>", 0, items);
 }
 
@@ -220,9 +220,9 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
        if (blk_count == 0)
        {
                // No connect blocks found; make a trivial default block
-               std::vector<KeyVal>* items;
+               ConfigItems* items;
                ConfigTag* tag = ConfigTag::create("connect", "<auto>", 0, items);
-               items->push_back(std::make_pair("allow", "*"));
+               (*items)["allow"] = "*";
                config_data.insert(std::make_pair("connect", tag));
                blk_count = 1;
        }
index 6fd7f405013e6fcc22092bd4c32ac5833bb5712b..11c82c03118400098651d36750ca15945be6d6c1 100644 (file)
@@ -81,8 +81,8 @@ class ModuleHttpConfig : public Module, public HTTPRequestEventListener
                                for (ConfigDataHash::iterator x = ServerInstance->Config->config_data.begin(); x != ServerInstance->Config->config_data.end(); ++x)
                                {
                                        data << "&lt;" << x->first << " ";
-                                       ConfigTag* tag = x->second;
-                                       for (std::vector<KeyVal>::const_iterator j = tag->getItems().begin(); j != tag->getItems().end(); j++)
+                                       const ConfigItems& items = x->second->getItems();
+                                       for (ConfigItems::const_iterator j = items.begin(); j != items.end(); j++)
                                        {
                                                data << Sanitize(j->first) << "=&quot;" << Sanitize(j->second) << "&quot; ";
                                        }