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/include/authorization.hpp b/include/authorization.hpp
index 634620b..997e504 100644
--- a/include/authorization.hpp
+++ b/include/authorization.hpp
@@ -13,6 +13,7 @@
 #include <pam_authenticate.hpp>
 
 #include <random>
+#include <utility>
 
 namespace crow
 {
@@ -165,7 +166,7 @@
 #ifdef BMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION
 static std::shared_ptr<persistent_data::UserSession>
     performTLSAuth(const crow::Request& req, Response& res,
-                   std::weak_ptr<persistent_data::UserSession> session)
+                   const std::weak_ptr<persistent_data::UserSession>& session)
 {
     if (auto sp = session.lock())
     {
@@ -244,7 +245,7 @@
 #ifdef BMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION
     if (req.session == nullptr && authMethodsConfig.tls)
     {
-        req.session = performTLSAuth(req, res, session);
+        req.session = performTLSAuth(req, res, std::move(session));
     }
 #endif
     if (req.session == nullptr && authMethodsConfig.xtoken)
diff --git a/include/dbus_monitor.hpp b/include/dbus_monitor.hpp
index f770ec3..089df76 100644
--- a/include/dbus_monitor.hpp
+++ b/include/dbus_monitor.hpp
@@ -108,7 +108,7 @@
         .privileges({"Login"})
         .websocket()
         .onopen([&](crow::websocket::Connection& conn,
-                    std::shared_ptr<bmcweb::AsyncResp>) {
+                    const std::shared_ptr<bmcweb::AsyncResp>&) {
             BMCWEB_LOG_DEBUG << "Connection " << &conn << " opened";
             sessions[&conn] = DbusWebsocketSession();
         })
diff --git a/include/ibm/locks.hpp b/include/ibm/locks.hpp
index b897fa7..201085f 100644
--- a/include/ibm/locks.hpp
+++ b/include/ibm/locks.hpp
@@ -15,7 +15,6 @@
 namespace ibm_mc_lock
 {
 
-namespace fs = std::filesystem;
 using SType = std::string;
 
 /*----------------------------------------
@@ -68,7 +67,7 @@
      * Returns : False (if not a Valid lock request)
      */
 
-    virtual bool isValidLockRequest(const LockRequest);
+    virtual bool isValidLockRequest(const LockRequest&);
 
     /*
      * This function implements the logic of checking if the incoming
@@ -78,7 +77,7 @@
      * Returns : False (if not conflicting)
      */
 
-    virtual bool isConflictRequest(const LockRequests);
+    virtual bool isConflictRequest(const LockRequests&);
     /*
      * Implements the core algorithm to find the conflicting
      * lock requests.
@@ -89,7 +88,7 @@
      * Returns : True (if conflicting)
      * Returns : False (if not conflicting)
      */
-    virtual bool isConflictRecord(const LockRequest, const LockRequest);
+    virtual bool isConflictRecord(const LockRequest&, const LockRequest&);
 
     /*
      * This function implements the logic of checking the conflicting
@@ -98,7 +97,7 @@
      *
      */
 
-    virtual Rc isConflictWithTable(const LockRequests);
+    virtual Rc isConflictWithTable(const LockRequests&);
     /*
      * This function implements the logic of checking the ownership of the
      * lock from the releaselock request.
@@ -153,7 +152,7 @@
      *
      */
 
-    RcAcquireLock acquireLock(const LockRequests);
+    RcAcquireLock acquireLock(const LockRequests&);
 
     /*
      * This function implements the logic for releasing the lock that are
@@ -260,9 +259,10 @@
     }
     std::ofstream persistentFile(fileName);
     // set the permission of the file to 640
-    fs::perms permission =
-        fs::perms::owner_read | fs::perms::owner_write | fs::perms::group_read;
-    fs::permissions(fileName, permission);
+    std::filesystem::perms permission = std::filesystem::perms::owner_read |
+                                        std::filesystem::perms::owner_write |
+                                        std::filesystem::perms::group_read;
+    std::filesystem::permissions(fileName, permission);
     nlohmann::json data;
     for (const auto& it : lockTable)
     {
@@ -329,7 +329,7 @@
     return std::make_pair(true, status);
 }
 
-inline RcAcquireLock Lock::acquireLock(const LockRequests lockRequestStructure)
+inline RcAcquireLock Lock::acquireLock(const LockRequests& lockRequestStructure)
 {
 
     // validate the lock request
@@ -466,7 +466,7 @@
     return true;
 }
 
-inline bool Lock::isValidLockRequest(const LockRequest refLockRecord)
+inline bool Lock::isValidLockRequest(const LockRequest& refLockRecord)
 {
 
     // validate the locktype
@@ -534,7 +534,7 @@
     return true;
 }
 
-inline Rc Lock::isConflictWithTable(const LockRequests refLockRequestStructure)
+inline Rc Lock::isConflictWithTable(const LockRequests& refLockRequestStructure)
 {
 
     uint32_t transactionId;
@@ -588,7 +588,7 @@
     return std::make_pair(false, transactionId);
 }
 
-inline bool Lock::isConflictRequest(const LockRequests refLockRequestStructure)
+inline bool Lock::isConflictRequest(const LockRequests& refLockRequestStructure)
 {
     // check for all the locks coming in as a part of single request
     // return conflict if any two lock requests are conflicting
@@ -647,8 +647,8 @@
     return true;
 }
 
-inline bool Lock::isConflictRecord(const LockRequest refLockRecord1,
-                                   const LockRequest refLockRecord2)
+inline bool Lock::isConflictRecord(const LockRequest& refLockRecord1,
+                                   const LockRequest& refLockRecord2)
 {
     // No conflict if both are read locks
 
diff --git a/include/kvm_websocket.hpp b/include/kvm_websocket.hpp
index fea3840..477582a 100644
--- a/include/kvm_websocket.hpp
+++ b/include/kvm_websocket.hpp
@@ -162,7 +162,7 @@
         .privileges({"ConfigureComponents", "ConfigureManager"})
         .websocket()
         .onopen([](crow::websocket::Connection& conn,
-                   std::shared_ptr<bmcweb::AsyncResp>) {
+                   const std::shared_ptr<bmcweb::AsyncResp>&) {
             BMCWEB_LOG_DEBUG << "Connection " << &conn << " opened";
 
             if (sessions.size() == maxSessions)
diff --git a/include/obmc_console.hpp b/include/obmc_console.hpp
index 06df7fd..020ef91 100644
--- a/include/obmc_console.hpp
+++ b/include/obmc_console.hpp
@@ -108,7 +108,7 @@
         .privileges({"ConfigureComponents", "ConfigureManager"})
         .websocket()
         .onopen([](crow::websocket::Connection& conn,
-                   std::shared_ptr<bmcweb::AsyncResp>) {
+                   const std::shared_ptr<bmcweb::AsyncResp>&) {
             BMCWEB_LOG_DEBUG << "Connection " << &conn << " opened";
 
             sessions.insert(&conn);
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 2c801c7..01c70e2 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -26,6 +26,7 @@
 #include <filesystem>
 #include <fstream>
 #include <regex>
+#include <utility>
 
 namespace crow
 {
@@ -66,9 +67,10 @@
                      {"status", "error"}};
 }
 
-inline void introspectObjects(const std::string& processName,
-                              const std::string& objectPath,
-                              std::shared_ptr<bmcweb::AsyncResp> transaction)
+inline void
+    introspectObjects(const std::string& processName,
+                      const std::string& objectPath,
+                      const std::shared_ptr<bmcweb::AsyncResp>& transaction)
 {
     if (transaction->res.jsonValue.is_null())
     {
@@ -130,7 +132,8 @@
 
 inline void getPropertiesForEnumerate(
     const std::string& objectPath, const std::string& service,
-    const std::string& interface, std::shared_ptr<bmcweb::AsyncResp> asyncResp)
+    const std::string& interface,
+    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
 {
     BMCWEB_LOG_DEBUG << "getPropertiesForEnumerate " << objectPath << " "
                      << service << " " << interface;
@@ -169,8 +172,9 @@
 // Find any results that weren't picked up by ObjectManagers, to be
 // called after all ObjectManagers are searched for and called.
 inline void findRemainingObjectsForEnumerate(
-    const std::string& objectPath, std::shared_ptr<GetSubTreeType> subtree,
-    std::shared_ptr<bmcweb::AsyncResp> asyncResp)
+    const std::string& objectPath,
+    const std::shared_ptr<GetSubTreeType>& subtree,
+    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
 {
     BMCWEB_LOG_DEBUG << "findRemainingObjectsForEnumerate";
     const nlohmann::json& dataJson = asyncResp->res.jsonValue["data"];
@@ -204,7 +208,7 @@
     InProgressEnumerateData(const std::string& objectPathIn,
                             std::shared_ptr<bmcweb::AsyncResp> asyncRespIn) :
         objectPath(objectPathIn),
-        asyncResp(asyncRespIn)
+        asyncResp(std::move(asyncRespIn))
     {}
 
     ~InProgressEnumerateData()
@@ -220,7 +224,7 @@
 inline void getManagedObjectsForEnumerate(
     const std::string& object_name, const std::string& object_manager_path,
     const std::string& connection_name,
-    std::shared_ptr<InProgressEnumerateData> transaction)
+    const std::shared_ptr<InProgressEnumerateData>& transaction)
 {
     BMCWEB_LOG_DEBUG << "getManagedObjectsForEnumerate " << object_name
                      << " object_manager_path " << object_manager_path
@@ -280,7 +284,7 @@
 
 inline void findObjectManagerPathForEnumerate(
     const std::string& object_name, const std::string& connection_name,
-    std::shared_ptr<InProgressEnumerateData> transaction)
+    const std::shared_ptr<InProgressEnumerateData>& transaction)
 {
     BMCWEB_LOG_DEBUG << "Finding objectmanager for path " << object_name
                      << " on connection:" << connection_name;
@@ -322,8 +326,8 @@
 // Uses GetObject to add the object info about the target /enumerate path to
 // the results of GetSubTree, as GetSubTree will not return info for the
 // target path, and then continues on enumerating the rest of the tree.
-inline void
-    getObjectAndEnumerate(std::shared_ptr<InProgressEnumerateData> transaction)
+inline void getObjectAndEnumerate(
+    const std::shared_ptr<InProgressEnumerateData>& transaction)
 {
     using GetObjectType =
         std::vector<std::pair<std::string, std::vector<std::string>>>;
@@ -1237,10 +1241,9 @@
     return 0;
 }
 
-inline void
-    handleMethodResponse(std::shared_ptr<InProgressActionData> transaction,
-                         sdbusplus::message::message& m,
-                         const std::string& returnType)
+inline void handleMethodResponse(
+    const std::shared_ptr<InProgressActionData>& transaction,
+    sdbusplus::message::message& m, const std::string& returnType)
 {
     nlohmann::json data;
 
@@ -1302,9 +1305,9 @@
     }
 }
 
-inline void
-    findActionOnInterface(std::shared_ptr<InProgressActionData> transaction,
-                          const std::string& connectionName)
+inline void findActionOnInterface(
+    const std::shared_ptr<InProgressActionData>& transaction,
+    const std::string& connectionName)
 {
     BMCWEB_LOG_DEBUG << "findActionOnInterface for connection "
                      << connectionName;
diff --git a/include/sessions.hpp b/include/sessions.hpp
index 95459b3..88fd487 100644
--- a/include/sessions.hpp
+++ b/include/sessions.hpp
@@ -269,7 +269,7 @@
         return nullptr;
     }
 
-    void removeSession(std::shared_ptr<UserSession> session)
+    void removeSession(const std::shared_ptr<UserSession>& session)
     {
 #ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE
         crow::ibm_mc_lock::Lock::getInstance().releaseLock(session->uniqueId);
diff --git a/include/vm_websocket.hpp b/include/vm_websocket.hpp
index 8521993..3d8abe4 100644
--- a/include/vm_websocket.hpp
+++ b/include/vm_websocket.hpp
@@ -160,7 +160,7 @@
         .privileges({"ConfigureComponents", "ConfigureManager"})
         .websocket()
         .onopen([](crow::websocket::Connection& conn,
-                   std::shared_ptr<bmcweb::AsyncResp>) {
+                   const std::shared_ptr<bmcweb::AsyncResp>&) {
             BMCWEB_LOG_DEBUG << "Connection " << &conn << " opened";
 
             if (session != nullptr)