[icinga-checkins] icinga.org: icinga2/master: Speed up item lookups for ConfigItem:: GetDefaultTemplates

git at icinga.org git at icinga.org
Mon Aug 29 08:46:58 CEST 2016


Module: icinga2
Branch: master
Commit: 32e6da1c60e58a41528e1a262ead2019595b93b4
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=32e6da1c60e58a41528e1a262ead2019595b93b4

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Mon Aug 29 08:40:46 2016 +0200

Speed up item lookups for ConfigItem::GetDefaultTemplates

refs #12575

---

 lib/config/configitem.cpp |   16 ++++++++++++----
 lib/config/configitem.hpp |    1 +
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp
index 71aadc3..00ab0e7 100644
--- a/lib/config/configitem.cpp
+++ b/lib/config/configitem.cpp
@@ -42,6 +42,7 @@ using namespace icinga;
 
 boost::mutex ConfigItem::m_Mutex;
 ConfigItem::TypeMap ConfigItem::m_Items;
+ConfigItem::TypeMap ConfigItem::m_DefaultTemplates;
 ConfigItem::ItemList ConfigItem::m_UnnamedItems;
 ConfigItem::IgnoredItemList ConfigItem::m_IgnoredItems;
 
@@ -342,6 +343,9 @@ void ConfigItem::Register(void)
 		}
 
 		m_Items[m_Type][m_Name] = this;
+
+		if (m_DefaultTmpl)
+			m_DefaultTemplates[m_Type][m_Name] = this;
 	}
 }
 
@@ -358,6 +362,7 @@ void ConfigItem::Unregister(void)
 	boost::mutex::scoped_lock lock(m_Mutex);
 	m_UnnamedItems.erase(std::remove(m_UnnamedItems.begin(), m_UnnamedItems.end(), this), m_UnnamedItems.end());
 	m_Items[m_Type].erase(m_Name);
+	m_DefaultTemplates[m_Type].erase(m_Name);
 }
 
 /**
@@ -650,6 +655,8 @@ std::vector<ConfigItem::Ptr> ConfigItem::GetItems(const String& type)
 	if (it == m_Items.end())
 		return items;
 
+	items.reserve(it->second.size());
+
 	for (const ItemMap::value_type& kv : it->second)
 	{
 		items.push_back(kv.second);
@@ -664,15 +671,16 @@ std::vector<ConfigItem::Ptr> ConfigItem::GetDefaultTemplates(const String& type)
 
 	boost::mutex::scoped_lock lock(m_Mutex);
 
-	auto it = m_Items.find(type);
+	auto it = m_DefaultTemplates.find(type);
 
-	if (it == m_Items.end())
+	if (it == m_DefaultTemplates.end())
 		return items;
 
+	items.reserve(it->second.size());
+
 	for (const ItemMap::value_type& kv : it->second)
 	{
-		if (kv.second->IsDefaultTemplate())
-			items.push_back(kv.second);
+		items.push_back(kv.second);
 	}
 
 	return items;
diff --git a/lib/config/configitem.hpp b/lib/config/configitem.hpp
index bfae063..0526722 100644
--- a/lib/config/configitem.hpp
+++ b/lib/config/configitem.hpp
@@ -101,6 +101,7 @@ private:
 	typedef std::map<String, ConfigItem::Ptr> ItemMap;
 	typedef std::map<String, ItemMap> TypeMap;
 	static TypeMap m_Items; /**< All registered configuration items. */
+	static TypeMap m_DefaultTemplates;
 
 	typedef std::vector<ConfigItem::Ptr> ItemList;
 	static ItemList m_UnnamedItems;



More information about the icinga-checkins mailing list