]> granicus.if.org Git - icinga2/commitdiff
Remove unnecessary dictionary lookups in the DebugHint class
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 17 Aug 2016 06:51:16 +0000 (08:51 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 17 Aug 2016 07:20:05 +0000 (09:20 +0200)
refs #12457

lib/config/expression.hpp

index 7eb5986213ffba866fe7bd38862bb26b832cf1d8..1c51cef7b59a164b8da225dfb8fe15fe2d8234e2 100644 (file)
@@ -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;
        }
 };