]> granicus.if.org Git - icinga2/commitdiff
Avoid using ConfigItem::GetObject when possible.
authorGunnar Beutner <gunnar@beutner.name>
Tue, 10 Dec 2013 19:01:38 +0000 (20:01 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 13 Dec 2013 13:07:57 +0000 (14:07 +0100)
Refs #5327

lib/config/configitem.cpp
lib/config/configitem.h
lib/config/typerule.cpp

index 4dc6eae7ec790c58900696f7d34781c99d9fc915..e9756141d5fc29ddef63331c6787e7030e9b102c 100644 (file)
@@ -219,6 +219,17 @@ ConfigItem::Ptr ConfigItem::GetObject(const String& type, const String& name)
        return ConfigItem::Ptr();
 }
 
+bool ConfigItem::HasObject(const String& type, const String& name)
+{
+       boost::mutex::scoped_lock lock(m_Mutex);
+
+       ConfigItem::ItemMap::iterator it;
+
+       it = m_Items.find(std::make_pair(type, name));
+
+       return (it != m_Items.end());
+}
+
 void ConfigItem::ValidateItem(void)
 {
        if (m_Validated)
index b16353f671b88ae525fe1f9568b0fbe2b13a9907..8adf4b6b816fe38799a856d6ec6b6a286e384eb0 100644 (file)
@@ -58,6 +58,7 @@ public:
 
        static ConfigItem::Ptr GetObject(const String& type,
            const String& name);
+       static bool HasObject(const String& type, const String& name);
 
        void ValidateItem(void);
 
index 0cb58cb97886f22d6bfb51af80be6df893aff6c3..6f45ef8a118b5d3b2b71da7e768698fe0e3febd4 100644 (file)
@@ -45,8 +45,6 @@ bool TypeRule::MatchName(const String& name) const
 
 bool TypeRule::MatchValue(const Value& value, String *hint) const
 {
-       ConfigItem::Ptr item;
-
        if (value.IsEmpty())
                return true;
 
@@ -78,9 +76,7 @@ bool TypeRule::MatchValue(const Value& value, String *hint) const
                        if (!value.IsScalar())
                                return false;
 
-                       item = ConfigItem::GetObject(m_NameType, value);
-
-                       if (!item) {
+                       if (!ConfigItem::HasObject(m_NameType, value)) {
                                *hint = "Object '" + value + "' of type '" + m_NameType + "' does not exist.";
                                return false;
                        }