tidy: fix performance-inefficient-string-concatenation

Tested by building and running the unit tests.

Change-Id: Ia7638172abcd737d6036bb5b2b96d03fb0a85562
Signed-off-by: Brad Bishop <bradbish@qti.qualcomm.com>
diff --git a/src/associations.cpp b/src/associations.cpp
index fc2703f..329f3d4 100644
--- a/src/associations.cpp
+++ b/src/associations.cpp
@@ -1,5 +1,7 @@
 #include "associations.hpp"
 
+#include "path.hpp"
+
 #include <boost/asio/steady_timer.hpp>
 #include <sdbusplus/exception.hpp>
 
@@ -268,11 +270,11 @@
 
         if (!forward.empty())
         {
-            objects[path + "/" + forward].emplace(objectPath);
+            objects[appendPathSegment(path, forward)].emplace(objectPath);
         }
         if (!reverse.empty())
         {
-            objects[objectPath + "/" + reverse].emplace(path);
+            objects[appendPathSegment(objectPath, reverse)].emplace(path);
         }
     }
     for (const auto& object : objects)
@@ -644,15 +646,19 @@
                               reverseType, owner, assocMaps);
 
         // Remove both sides of the association from assocMaps.ifaces
-        removeAssociationIfacesEntry(io, forwardPath + '/' + forwardType,
-                                     reversePath, assocMaps, server);
-        removeAssociationIfacesEntry(io, reversePath + '/' + reverseType,
-                                     forwardPath, assocMaps, server);
+        removeAssociationIfacesEntry(
+            io, appendPathSegment(forwardPath, forwardType), reversePath,
+            assocMaps, server);
+        removeAssociationIfacesEntry(
+            io, appendPathSegment(reversePath, reverseType), forwardPath,
+            assocMaps, server);
 
         // Remove both sides of the association from assocMaps.owners
-        removeAssociationOwnersEntry(forwardPath + '/' + forwardType,
-                                     reversePath, owner, assocMaps);
-        removeAssociationOwnersEntry(reversePath + '/' + reverseType,
-                                     forwardPath, owner, assocMaps);
+        removeAssociationOwnersEntry(
+            appendPathSegment(forwardPath, forwardType), reversePath, owner,
+            assocMaps);
+        removeAssociationOwnersEntry(
+            appendPathSegment(reversePath, reverseType), forwardPath, owner,
+            assocMaps);
     }
 }
diff --git a/src/handler.cpp b/src/handler.cpp
index 5575f2d..89c9913 100644
--- a/src/handler.cpp
+++ b/src/handler.cpp
@@ -1,5 +1,6 @@
 #include "handler.hpp"
 
+#include "path.hpp"
 #include "types.hpp"
 
 #include <xyz/openbmc_project/Common/error.hpp>
@@ -427,7 +428,8 @@
     for (const auto& subtreePath : subtreePaths)
     {
         // Form the association path
-        std::string associationPathStr = subtreePath + "/" + association;
+        std::string associationPathStr =
+            appendPathSegment(subtreePath, association);
         sdbusplus::message::object_path associationPath(associationPathStr);
 
         auto associatedSubTree =
@@ -453,7 +455,8 @@
     for (const auto& subtreePath : subtreePaths)
     {
         // Form the association path
-        std::string associationPathStr = subtreePath + "/" + association;
+        std::string associationPathStr =
+            appendPathSegment(subtreePath, association);
         sdbusplus::message::object_path associationPath(associationPathStr);
 
         auto associatedSubTree = getAssociatedSubTreePaths(
diff --git a/src/path.hpp b/src/path.hpp
new file mode 100644
index 0000000..f3bd2ce
--- /dev/null
+++ b/src/path.hpp
@@ -0,0 +1,10 @@
+#include <string>
+
+inline std::string appendPathSegment(const std::string& target,
+                                     const std::string& segment)
+{
+    std::string newPath;
+    newPath.reserve(target.size() + 1 + segment.size());
+    newPath.append(target).append("/").append(segment);
+    return newPath;
+}