Lots of performance improvements

(In the voice of the kid from sixth sense) I see string copies...

Apparently there are a lot of places we make unnecessary copies. This
fixes all of them.

Not sure how to split this up into smaller patches, or if it even needs
split up. It seems pretty easy to review to me, because basically every
diff is identical.

Change-Id: I22b4ae4f96f7e4082d2bc701098a04f7bed95369
Signed-off-by: Ed Tanous <ed@tanous.net>
Signed-off-by: Wludzik, Jozef <jozef.wludzik@intel.com>
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index 91e54bb..6480861 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -25,6 +25,7 @@
 #include <utils/json_utils.hpp>
 
 #include <cmath>
+#include <utility>
 #include <variant>
 
 namespace redfish
@@ -89,7 +90,7 @@
     };
 
     SensorsAsyncResp(crow::Response& response, const std::string& chassisIdIn,
-                     const std::vector<const char*> typesIn,
+                     const std::vector<const char*>& typesIn,
                      const std::string_view& subNode) :
         res(response),
         chassisId(chassisIdIn), types(typesIn), chassisSubNode(subNode)
@@ -97,7 +98,7 @@
 
     // Store extra data about sensor mapping and return it in callback
     SensorsAsyncResp(crow::Response& response, const std::string& chassisIdIn,
-                     const std::vector<const char*> typesIn,
+                     const std::vector<const char*>& typesIn,
                      const std::string_view& subNode,
                      DataCompleteCb&& creationComplete) :
         res(response),
@@ -222,8 +223,8 @@
  */
 template <typename Callback>
 void getObjectsWithConnection(
-    std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp,
-    const std::shared_ptr<boost::container::flat_set<std::string>> sensorNames,
+    const std::shared_ptr<SensorsAsyncResp>& SensorsAsyncResp,
+    const std::shared_ptr<boost::container::flat_set<std::string>>& sensorNames,
     Callback&& callback)
 {
     BMCWEB_LOG_DEBUG << "getObjectsWithConnection enter";
@@ -319,9 +320,10 @@
  * made, and eliminate Power sensors when a Thermal request is made.
  */
 inline void reduceSensorList(
-    std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp,
+    const std::shared_ptr<SensorsAsyncResp>& SensorsAsyncResp,
     const std::vector<std::string>* allSensors,
-    std::shared_ptr<boost::container::flat_set<std::string>> activeSensors)
+    const std::shared_ptr<boost::container::flat_set<std::string>>&
+        activeSensors)
 {
     if (SensorsAsyncResp == nullptr)
     {
@@ -361,7 +363,7 @@
  * @param callback  Callback for next step to get valid chassis path
  */
 template <typename Callback>
-void getValidChassisPath(std::shared_ptr<SensorsAsyncResp> asyncResp,
+void getValidChassisPath(const std::shared_ptr<SensorsAsyncResp>& asyncResp,
                          Callback&& callback)
 {
     BMCWEB_LOG_DEBUG << "checkChassisId enter";
@@ -417,7 +419,7 @@
  * @param callback  Callback for next step in gathered sensor processing
  */
 template <typename Callback>
-void getChassis(std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
+void getChassis(const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
                 Callback&& callback)
 {
     BMCWEB_LOG_DEBUG << "getChassis enter";
@@ -563,8 +565,9 @@
  * @param callback Callback to invoke when object paths obtained.
  */
 template <typename Callback>
-void getObjectManagerPaths(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp,
-                           Callback&& callback)
+void getObjectManagerPaths(
+    const std::shared_ptr<SensorsAsyncResp>& SensorsAsyncResp,
+    Callback&& callback)
 {
     BMCWEB_LOG_DEBUG << "getObjectManagerPaths enter";
     const std::array<std::string, 1> interfaces = {
@@ -793,7 +796,7 @@
  */
 inline void objectInterfacesToJson(
     const std::string& sensorName, const std::string& sensorType,
-    std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
+    const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
     const boost::container::flat_map<
         std::string, boost::container::flat_map<std::string, SensorVariant>>&
         interfacesDict,
@@ -1041,8 +1044,8 @@
     BMCWEB_LOG_DEBUG << "Added sensor " << sensorName;
 }
 
-inline void
-    populateFanRedundancy(std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp)
+inline void populateFanRedundancy(
+    const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp)
 {
     crow::connections::systemBus->async_method_call(
         [sensorsAsyncResp](const boost::system::error_code ec,
@@ -1248,7 +1251,8 @@
             "xyz.openbmc_project.Control.FanRedundancy"});
 }
 
-inline void sortJSONResponse(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp)
+inline void
+    sortJSONResponse(const std::shared_ptr<SensorsAsyncResp>& SensorsAsyncResp)
 {
     nlohmann::json& response = SensorsAsyncResp->res.jsonValue;
     std::array<std::string, 2> sensorHeaders{"Temperatures", "Fans"};
@@ -1294,7 +1298,7 @@
  * @return Inventory item within vector, or nullptr if no match found.
  */
 inline InventoryItem* findInventoryItem(
-    std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
+    const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems,
     const std::string& invItemObjPath)
 {
     for (InventoryItem& inventoryItem : *inventoryItems)
@@ -1314,7 +1318,7 @@
  * @return Inventory item within vector, or nullptr if no match found.
  */
 inline InventoryItem* findInventoryItemForSensor(
-    std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
+    const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems,
     const std::string& sensorObjPath)
 {
     for (InventoryItem& inventoryItem : *inventoryItems)
@@ -1361,10 +1365,9 @@
  * @param invItemObjPath D-Bus object path of inventory item.
  * @param sensorObjPath D-Bus object path of sensor
  */
-inline void
-    addInventoryItem(std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
-                     const std::string& invItemObjPath,
-                     const std::string& sensorObjPath)
+inline void addInventoryItem(
+    const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems,
+    const std::string& invItemObjPath, const std::string& sensorObjPath)
 {
     // Look for inventory item in vector
     InventoryItem* inventoryItem =
@@ -1624,8 +1627,8 @@
  */
 template <typename Callback>
 static void getInventoryItemsConnections(
-    std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
-    std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
+    const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
+    const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems,
     Callback&& callback)
 {
     BMCWEB_LOG_DEBUG << "getInventoryItemsConnections enter";
@@ -1711,9 +1714,9 @@
  */
 template <typename Callback>
 static void getInventoryItemAssociations(
-    std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
-    const std::shared_ptr<boost::container::flat_set<std::string>> sensorNames,
-    std::shared_ptr<boost::container::flat_map<std::string, std::string>>
+    const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
+    const std::shared_ptr<boost::container::flat_set<std::string>>& sensorNames,
+    const std::shared_ptr<boost::container::flat_map<std::string, std::string>>&
         objectMgrPaths,
     Callback&& callback)
 {
@@ -2074,7 +2077,7 @@
  */
 template <typename Callback>
 void getPowerSupplyAttributesData(
-    std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
+    const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
     std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
     const boost::container::flat_map<std::string, std::string>&
         psAttributesConnections,
@@ -2415,12 +2418,12 @@
  * @param inventoryItems Inventory items associated with the sensors.
  */
 inline void getSensorData(
-    std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp,
-    const std::shared_ptr<boost::container::flat_set<std::string>> sensorNames,
+    const std::shared_ptr<SensorsAsyncResp>& SensorsAsyncResp,
+    const std::shared_ptr<boost::container::flat_set<std::string>>& sensorNames,
     const boost::container::flat_set<std::string>& connections,
-    std::shared_ptr<boost::container::flat_map<std::string, std::string>>
+    const std::shared_ptr<boost::container::flat_map<std::string, std::string>>&
         objectMgrPaths,
-    std::shared_ptr<std::vector<InventoryItem>> inventoryItems)
+    const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems)
 {
     BMCWEB_LOG_DEBUG << "getSensorData enter";
     // Get managed objects from all services exposing sensors
@@ -2599,18 +2602,17 @@
 }
 
 inline void processSensorList(
-    std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp,
-    std::shared_ptr<boost::container::flat_set<std::string>> sensorNames)
+    const std::shared_ptr<SensorsAsyncResp>& SensorsAsyncResp,
+    const std::shared_ptr<boost::container::flat_set<std::string>>& sensorNames)
 {
     auto getConnectionCb =
         [SensorsAsyncResp, sensorNames](
             const boost::container::flat_set<std::string>& connections) {
             BMCWEB_LOG_DEBUG << "getConnectionCb enter";
             auto getObjectManagerPathsCb =
-                [SensorsAsyncResp, sensorNames, connections](
-                    std::shared_ptr<
-                        boost::container::flat_map<std::string, std::string>>
-                        objectMgrPaths) {
+                [SensorsAsyncResp, sensorNames,
+                 connections](const std::shared_ptr<boost::container::flat_map<
+                                  std::string, std::string>>& objectMgrPaths) {
                     BMCWEB_LOG_DEBUG << "getObjectManagerPathsCb enter";
                     auto getInventoryItemsCb =
                         [SensorsAsyncResp, sensorNames, connections,
@@ -2621,7 +2623,7 @@
                             // Get sensor data and store results in JSON
                             getSensorData(SensorsAsyncResp, sensorNames,
                                           connections, objectMgrPaths,
-                                          inventoryItems);
+                                          std::move(inventoryItems));
                             BMCWEB_LOG_DEBUG << "getInventoryItemsCb exit";
                         };
 
@@ -2649,7 +2651,8 @@
  *        chassis.
  * @param SensorsAsyncResp   Pointer to object holding response data
  */
-inline void getChassisData(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp)
+inline void
+    getChassisData(const std::shared_ptr<SensorsAsyncResp>& SensorsAsyncResp)
 {
     BMCWEB_LOG_DEBUG << "getChassisData enter";
     auto getChassisCb =
@@ -2657,7 +2660,7 @@
             std::shared_ptr<boost::container::flat_set<std::string>>
                 sensorNames) {
             BMCWEB_LOG_DEBUG << "getChassisCb enter";
-            processSensorList(SensorsAsyncResp, sensorNames);
+            processSensorList(SensorsAsyncResp, std::move(sensorNames));
             BMCWEB_LOG_DEBUG << "getChassisCb exit";
         };
     SensorsAsyncResp->res.jsonValue["Redundancy"] = nlohmann::json::array();
@@ -2706,7 +2709,7 @@
  * @param chassisSubNode   Chassis Node for which the query has to happen
  */
 inline void setSensorsOverride(
-    std::shared_ptr<SensorsAsyncResp> sensorAsyncResp,
+    const std::shared_ptr<SensorsAsyncResp>& sensorAsyncResp,
     std::unordered_map<std::string, std::vector<nlohmann::json>>&
         allCollections)
 {
@@ -2743,11 +2746,10 @@
         }
     }
 
-    auto getChassisSensorListCb = [sensorAsyncResp,
-                                   overrideMap](const std::shared_ptr<
-                                                boost::container::flat_set<
-                                                    std::string>>
-                                                    sensorsList) {
+    auto getChassisSensorListCb = [sensorAsyncResp, overrideMap](
+                                      const std::shared_ptr<
+                                          boost::container::flat_set<
+                                              std::string>>& sensorsList) {
         // Match sensor names in the PATCH request to those managed by the
         // chassis node
         const std::shared_ptr<boost::container::flat_set<std::string>>
@@ -2859,7 +2861,7 @@
  * @param chassisSubNode   Chassis Node for which the query has to happen
  */
 inline void checkAndDoSensorsOverride(
-    std::shared_ptr<SensorsAsyncResp> sensorAsyncResp,
+    const std::shared_ptr<SensorsAsyncResp>& sensorAsyncResp,
     std::unordered_map<std::string, std::vector<nlohmann::json>>&
         allCollections)
 {
@@ -3029,8 +3031,9 @@
                 sensors::node::sensors);
 
         auto getChassisCb =
-            [asyncResp](std::shared_ptr<boost::container::flat_set<std::string>>
-                            sensorNames) {
+            [asyncResp](
+                const std::shared_ptr<boost::container::flat_set<std::string>>&
+                    sensorNames) {
                 BMCWEB_LOG_DEBUG << "getChassisCb enter";
 
                 nlohmann::json& entriesArray =