]> granicus.if.org Git - icinga2/commitdiff
Fix complexity class for Dictionary::Get
authorGunnar Beutner <gunnar@beutner.name>
Tue, 31 Mar 2015 08:39:02 +0000 (10:39 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Tue, 31 Mar 2015 08:40:34 +0000 (10:40 +0200)
fixes #8919

lib/base/dictionary.cpp
lib/base/dictionary.hpp

index 10c5f7bf1248d7deec2edb94de59200a9afff5fb..e82e36b1e91b91e2fdbab6cd9f8669bbbb70ccea 100644 (file)
@@ -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.
  *
index 71b206f601831f1212efc43801fa49e2b2c2a7fc..9a003aa360761cddbebd8495cf332fd8c631a000 100644 (file)
@@ -49,7 +49,6 @@ public:
 
        typedef std::pair<String, Value> Pair;
 
-       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;