[icinga-checkins] icinga.org: icinga2/master: Remove unnecessary dictionary lookups in the DebugHint class

git at icinga.org git at icinga.org
Wed Aug 17 09:25:17 CEST 2016


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

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Wed Aug 17 08:51:16 2016 +0200

Remove unnecessary dictionary lookups in the DebugHint class

refs #12457

---

 lib/config/expression.hpp |   49 ++++++++++++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 21 deletions(-)

diff --git a/lib/config/expression.hpp b/lib/config/expression.hpp
index 7eb5986..1c51cef 100644
--- a/lib/config/expression.hpp
+++ b/lib/config/expression.hpp
@@ -45,12 +45,19 @@ public:
 	inline void AddMessage(const String& message, const DebugInfo& di)
 	{
 		Array::Ptr amsg = new Array();
-		amsg->Add(message);
-		amsg->Add(di.Path);
-		amsg->Add(di.FirstLine);
-		amsg->Add(di.FirstColumn);
-		amsg->Add(di.LastLine);
-		amsg->Add(di.LastColumn);
+
+		{
+			ObjectLock olock(amsg);
+
+			amsg->Reserve(6);
+			amsg->Add(message);
+			amsg->Add(di.Path);
+			amsg->Add(di.FirstLine);
+			amsg->Add(di.FirstColumn);
+			amsg->Add(di.LastLine);
+			amsg->Add(di.LastColumn);
+		}
+
 		GetMessages()->Add(amsg);
 	}
 
@@ -58,14 +65,14 @@ public:
 	{
 		Dictionary::Ptr children = GetChildren();
 
-		Dictionary::Ptr child = children->Get(name);
+		Value vchild;
 
-		if (!child) {
-			child = new Dictionary();
-			children->Set(name, child);
+		if (!children->Get(name, &vchild)) {
+			vchild = new Dictionary();
+			children->Set(name, vchild);
 		}
 
-		return DebugHint(child);
+		return DebugHint(vchild);
 	}
 
 	Dictionary::Ptr ToDictionary(void) const
@@ -81,14 +88,14 @@ private:
 		if (!m_Hints)
 			m_Hints = new Dictionary();
 
-		Array::Ptr messages = m_Hints->Get("messages");
+		Value vmessages;
 
-		if (!messages) {
-			messages = new Array();
-			m_Hints->Set("messages", messages);
+		if (!m_Hints->Get("messages", &vmessages)) {
+			vmessages = new Array();
+			m_Hints->Set("messages", vmessages);
 		}
 
-		return messages;
+		return vmessages;
 	}
 
 	Dictionary::Ptr GetChildren(void)
@@ -96,14 +103,14 @@ private:
 		if (!m_Hints)
 			m_Hints = new Dictionary();
 
-		Dictionary::Ptr children = m_Hints->Get("properties");
+		Value vchildren;
 
-		if (!children) {
-			children = new Dictionary;
-			m_Hints->Set("properties", children);
+		if (!m_Hints->Get("properties", &vchildren)) {
+			vchildren = new Dictionary();
+			m_Hints->Set("properties", vchildren);
 		}
 
-		return children;
+		return vchildren;
 	}
 };
 



More information about the icinga-checkins mailing list