[icinga-checkins] icinga.org: icinga2/next: Optimize Service::GetHost.

git at icinga.org git at icinga.org
Mon Nov 11 09:28:34 CET 2013


Module: icinga2
Branch: next
Commit: f7171e3e90243dbdd4c2ede90e82151543d94c35
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=f7171e3e90243dbdd4c2ede90e82151543d94c35

Author: Gunnar Beutner <gunnar at beutner.name>
Date:   Sun Nov 10 22:04:18 2013 +0100

Optimize Service::GetHost.

Refs #5049

---

 lib/icinga/service.cpp |   11 ++++++-----
 lib/icinga/service.h   |    2 ++
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp
index dbec5f4..1eb4d84 100644
--- a/lib/icinga/service.cpp
+++ b/lib/icinga/service.cpp
@@ -72,9 +72,10 @@ void Service::OnConfigLoaded(void)
 		}
 	}
 
-	Host::Ptr host = GetHost();
-	if (host)
-		host->AddService(GetSelf());
+	m_Host = Host::GetByName(GetHostRaw());
+
+	if (m_Host)
+		m_Host->AddService(GetSelf());
 
 	UpdateSlaveNotifications();
 }
@@ -95,7 +96,7 @@ Service::Ptr Service::GetByNamePair(const String& hostName, const String& servic
 
 Host::Ptr Service::GetHost(void) const
 {
-	return Host::GetByName(GetHostRaw());
+	return m_Host;
 }
 
 bool Service::IsHostCheck(void) const
@@ -227,7 +228,7 @@ std::set<Host::Ptr> Service::GetParentHosts(void) const
 	if (dependencies) {
 		ObjectLock olock(dependencies);
 
-		BOOST_FOREACH(const Value& dependency, dependencies) {
+		BOOST_FOREACH(const String& dependency, dependencies) {
 			Host::Ptr host = Host::GetByName(dependency);
 
 			if (!host)
diff --git a/lib/icinga/service.h b/lib/icinga/service.h
index 1ae8fca..c11e0ea 100644
--- a/lib/icinga/service.h
+++ b/lib/icinga/service.h
@@ -255,6 +255,8 @@ protected:
 	virtual void OnConfigLoaded(void);
 
 private:
+	Host::Ptr m_Host;
+
 	bool m_CheckRunning;
 	long m_SchedulingOffset;
 





More information about the icinga-checkins mailing list