From: Gunnar Beutner <gunnar@beutner.name>
Date: Tue, 31 Mar 2015 08:39:02 +0000 (+0200)
Subject: Fix complexity class for Dictionary::Get
X-Git-Tag: v2.4.0~745
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=43f709c22ae51110f720dca325a067279aa94ace;p=icinga2

Fix complexity class for Dictionary::Get

fixes #8919
---

diff --git a/lib/base/dictionary.cpp b/lib/base/dictionary.cpp
index 8e957da49..9b84cca69 100644
--- a/lib/base/dictionary.cpp
+++ b/lib/base/dictionary.cpp
@@ -27,70 +27,25 @@ using namespace icinga;
 
 REGISTER_PRIMITIVE_TYPE(Dictionary, Dictionary::GetPrototype());
 
-/**
- * Compares dictionary keys using the less operator.
- */
-struct DictionaryKeyLessComparer
-{
-	/**
-	 * Compares two keys.
-	 *
-	 * @param a The first key.
-	 * @param b The second key.
-	 * @returns true if the first key is less than the second key, false
-	 *		 otherwise
-	 */
-	bool operator()(const std::pair<String, Value>& a, const char *b)
-	{
-		return a.first < b;
-	}
-
-	/**
-	 * Compares two keys.
-	 *
-	 * @param a The first key.
-	 * @param b The second key.
-	 * @returns true if the first key is less than the second key, false
-	 *		 otherwise
-	 */
-	bool operator()(const char *a, const std::pair<String, Value>& b)
-	{
-		return a < b.first;
-	}
-};
-
 /**
  * Retrieves a value from a dictionary.
  *
  * @param key The key whose value should be retrieved.
  * @returns The value of an empty value if the key was not found.
  */
-Value Dictionary::Get(const char *key) const
+Value Dictionary::Get(const String& key) const
 {
 	ASSERT(!OwnsLock());
 	ObjectLock olock(this);
 
-	std::map<String, Value>::const_iterator it;
-
-	it = std::lower_bound(m_Data.begin(), m_Data.end(), key, DictionaryKeyLessComparer());
+	std::map<String, Value>::const_iterator it = m_Data.find(key);
 
-	if (it == m_Data.end() || DictionaryKeyLessComparer()(key, *it))
+	if (it == m_Data.end())
 		return Empty;
 
 	return it->second;
 }
 
-/**
- * Retrieves a value from the dictionary.
- *
- * @param key The key whose value should be retrieved.
- * @returns The value or an empty value if the key was not found.
- */
-Value Dictionary::Get(const String& key) const
-{
-	return Get(key.CStr());
-}
-
 /**
  * Sets a value in the dictionary.
  *
diff --git a/lib/base/dictionary.hpp b/lib/base/dictionary.hpp
index ef3902021..89a0ceccb 100644
--- a/lib/base/dictionary.hpp
+++ b/lib/base/dictionary.hpp
@@ -55,7 +55,6 @@ public:
 	inline ~Dictionary(void)
 	{ }
 
-	Value Get(const char *key) const;
 	Value Get(const String& key) const;
 	void Set(const String& key, const Value& value);
 	bool Contains(const String& key) const;