[icinga-checkins] icinga.org: icinga2/master: Remove unnecessary Dictionary::Contains calls

git at icinga.org git at icinga.org
Tue Aug 16 22:04:07 CEST 2016


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

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Tue Aug 16 22:03:30 2016 +0200

Remove unnecessary Dictionary::Contains calls

fixes #12457

---

 lib/base/configobject.cpp |    4 +---
 lib/base/scriptglobal.cpp |   12 ++++++++----
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/lib/base/configobject.cpp b/lib/base/configobject.cpp
index 7f4887b..148ff0e 100644
--- a/lib/base/configobject.cpp
+++ b/lib/base/configobject.cpp
@@ -159,11 +159,9 @@ void ConfigObject::ModifyAttribute(const String& attr, const Value& value, bool
 			const String& key = tokens[i];
 			prefix += "." + key;
 
-			if (!dict->Contains(key)) {
+			if (!dict->Get(key, &current)) {
 				current = new Dictionary();
 				dict->Set(key, current);
-			} else {
-				current = dict->Get(key);
 			}
 		}
 
diff --git a/lib/base/scriptglobal.cpp b/lib/base/scriptglobal.cpp
index d1dd268..48a1d66 100644
--- a/lib/base/scriptglobal.cpp
+++ b/lib/base/scriptglobal.cpp
@@ -36,14 +36,16 @@ Dictionary::Ptr ScriptGlobal::m_Globals = new Dictionary();
 
 Value ScriptGlobal::Get(const String& name, const Value *defaultValue)
 {
-	if (!m_Globals->Contains(name)) {
+	Value result;
+
+	if (!m_Globals->Get(name, &result)) {
 		if (defaultValue)
 			return *defaultValue;
 
 		BOOST_THROW_EXCEPTION(std::invalid_argument("Tried to access undefined script variable '" + name + "'"));
 	}
 
-	return m_Globals->Get(name);
+	return result;
 }
 
 void ScriptGlobal::Set(const String& name, const Value& value)
@@ -63,12 +65,14 @@ void ScriptGlobal::Set(const String& name, const Value& value)
 			const String& token = tokens[i];
 
 			if (i + 1 != tokens.size()) {
-				if (!parent->Contains(token)) {
+				Value vparent;
+
+				if (!parent->Get(token, &vparent)) {
 					Dictionary::Ptr dict = new Dictionary();
 					parent->Set(token, dict);
 					parent = dict;
 				} else {
-					parent = parent->Get(token);
+					parent = vparent;
 				}
 			}
 		}



More information about the icinga-checkins mailing list