From 46b0392962325a2d9f17d7f4df2971915afaa8c5 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 31 Mar 2015 10:39:02 +0200 Subject: [PATCH] Fix complexity class for Dictionary::Get fixes #8919 --- lib/base/dictionary.cpp | 51 +++-------------------------------------- lib/base/dictionary.hpp | 1 - 2 files changed, 3 insertions(+), 49 deletions(-) diff --git a/lib/base/dictionary.cpp b/lib/base/dictionary.cpp index 10c5f7bf1..e82e36b1e 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& 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& 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::const_iterator it; - - it = std::lower_bound(m_Data.begin(), m_Data.end(), key, DictionaryKeyLessComparer()); + std::map::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 71b206f60..9a003aa36 100644 --- a/lib/base/dictionary.hpp +++ b/lib/base/dictionary.hpp @@ -49,7 +49,6 @@ public: typedef std::pair 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; -- 2.40.0