From: Gunnar Beutner Date: Tue, 10 Dec 2013 19:01:38 +0000 (+0100) Subject: Avoid using ConfigItem::GetObject when possible. X-Git-Tag: v0.0.6~42^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b5792a0b8188094720cd02999286ee15ca6d5908;p=icinga2 Avoid using ConfigItem::GetObject when possible. Refs #5327 --- diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index 4dc6eae7e..e9756141d 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -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) diff --git a/lib/config/configitem.h b/lib/config/configitem.h index b16353f67..8adf4b6b8 100644 --- a/lib/config/configitem.h +++ b/lib/config/configitem.h @@ -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); diff --git a/lib/config/typerule.cpp b/lib/config/typerule.cpp index 0cb58cb97..6f45ef8a1 100644 --- a/lib/config/typerule.cpp +++ b/lib/config/typerule.cpp @@ -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; }