switch map to unordered_map
Generally, unordered_maps should be preferred over map because they have
faster access times (O(1)) and tend to allocate less dynamic memory. We
do not rely on ordered iteration in any current use of maps, so it is
safe to do a full replace.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ieaa28ac7f70f9913d13d25142fea9861d49bb23f
diff --git a/manager/json-config.hpp b/manager/json-config.hpp
index 1e63bc4..3b836a1 100644
--- a/manager/json-config.hpp
+++ b/manager/json-config.hpp
@@ -96,8 +96,10 @@
void ifacesAddedCallback(sdbusplus::message::message& msg)
{
sdbusplus::message::object_path path;
- std::map<std::string,
- std::map<std::string, std::variant<std::vector<std::string>>>>
+ std::unordered_map<
+ std::string,
+ std::unordered_map<std::string,
+ std::variant<std::vector<std::string>>>>
interfaces;
msg.read(path, interfaces);
diff --git a/manager/json-parser.hpp b/manager/json-parser.hpp
index 4388a21..06fb096 100644
--- a/manager/json-parser.hpp
+++ b/manager/json-parser.hpp
@@ -16,11 +16,12 @@
using Json = nlohmann::json;
using LedAction = std::set<phosphor::led::Layout::LedAction>;
-using LedMap = std::map<std::string, LedAction>;
+using LedMap = std::unordered_map<std::string, LedAction>;
// Priority for a particular LED needs to stay SAME across all groups
// phosphor::led::Layout::Action can only be one of `Blink` and `On`
-using PriorityMap = std::map<std::string, phosphor::led::Layout::Action>;
+using PriorityMap =
+ std::unordered_map<std::string, phosphor::led::Layout::Action>;
/** @brief Parse LED JSON file and output Json object
*
@@ -70,7 +71,7 @@
*
* @param[in] name - led name member of each group
* @param[in] priority - member priority of each group
- * @param[out] priorityMap - std::map, key:name, value:priority
+ * @param[out] priorityMap - std::unordered_map, key:name, value:priority
*
* @return
*/
@@ -100,7 +101,7 @@
/** @brief Load JSON config and return led map (JSON version 1)
*
- * @return LedMap - Generated an std::map of LedAction
+ * @return LedMap - Generated an std::unordered_map of LedAction
*/
const LedMap loadJsonConfigV1(const Json& json)
{
@@ -138,7 +139,7 @@
ledActions.emplace(ledAction);
}
- // Generated an std::map of LedGroupNames to std::set of LEDs
+ // Generated an std::unordered_map of LedGroupNames to std::set of LEDs
// containing the name and properties.
ledMap.emplace(objpath, ledActions);
}
@@ -148,7 +149,7 @@
/** @brief Load JSON config and return led map
*
- * @return LedMap - Generated an std::map of LedAction
+ * @return LedMap - Generated an std::unordered_map of LedAction
*/
const LedMap loadJsonConfig(const fs::path& path)
{
@@ -172,7 +173,7 @@
/** @brief Get led map from LED groups JSON config
*
* @param[in] config - Path to the JSON config.
- * @return LedMap - Generated an std::map of LedAction
+ * @return LedMap - Generated an std::unordered_map of LedAction
*
* @note if config is an empty string, daemon will interrogate dbus for
* compatible strings.
diff --git a/manager/ledlayout.hpp b/manager/ledlayout.hpp
index 6d617b4..3424606 100644
--- a/manager/ledlayout.hpp
+++ b/manager/ledlayout.hpp
@@ -2,9 +2,9 @@
#include <xyz/openbmc_project/Led/Physical/server.hpp>
-#include <map>
#include <set>
#include <string>
+#include <unordered_map>
namespace phosphor
{
diff --git a/manager/manager.hpp b/manager/manager.hpp
index 20f8aaa..88875d1 100644
--- a/manager/manager.hpp
+++ b/manager/manager.hpp
@@ -3,9 +3,9 @@
#include "ledlayout.hpp"
#include "utils.hpp"
-#include <map>
#include <set>
#include <string>
+#include <unordered_map>
namespace phosphor
{
@@ -69,7 +69,7 @@
}
using group = std::set<phosphor::led::Layout::LedAction>;
- using LedLayout = std::map<std::string, group>;
+ using LedLayout = std::unordered_map<std::string, group>;
/** @brief static global map constructed at compile time */
const LedLayout& ledMap;
@@ -131,7 +131,7 @@
sdbusplus::bus::bus& bus;
/** Map of physical LED path to service name */
- std::map<std::string, std::string> phyLeds{};
+ std::unordered_map<std::string, std::string> phyLeds{};
/** DBusHandler class handles the D-Bus operations */
DBusHandler dBusHandler;