From ad9394f4fdb69f3f3376d7377fac0a22568aed7c Mon Sep 17 00:00:00 2001
From: Milian Wolff <mail@milianw.de>
Date: Fri, 15 Jan 2016 14:19:33 +0100
Subject: [PATCH] Remove temporary allocations in
 cmMacroHelper::InvokeInitialPass.

This code used to convert std::string's to raw C strings only to
put that back into a std::string. This patch thus removes ~70k
temporary allocations when running the CMake daemon on KDevelop.

This hotspot was found with heaptrack.
---
 Source/cmMacroCommand.cxx | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx
index e4026b084c..71de7a7230 100644
--- a/Source/cmMacroCommand.cxx
+++ b/Source/cmMacroCommand.cxx
@@ -146,16 +146,14 @@ bool cmMacroHelperCommand::InvokeInitialPass
         // replace formal arguments
         for (unsigned int j = 0; j < variables.size(); ++j)
           {
-          cmSystemTools::ReplaceString(arg.Value, variables[j].c_str(),
-                                       expandedArgs[j].c_str());
+          cmSystemTools::ReplaceString(arg.Value, variables[j],
+                                       expandedArgs[j]);
           }
         // replace argc
-        cmSystemTools::ReplaceString(arg.Value, "${ARGC}",argcDef.c_str());
+        cmSystemTools::ReplaceString(arg.Value, "${ARGC}", argcDef);
 
-        cmSystemTools::ReplaceString(arg.Value, "${ARGN}",
-                                     expandedArgn.c_str());
-        cmSystemTools::ReplaceString(arg.Value, "${ARGV}",
-                                     expandedArgv.c_str());
+        cmSystemTools::ReplaceString(arg.Value, "${ARGN}", expandedArgn);
+        cmSystemTools::ReplaceString(arg.Value, "${ARGV}", expandedArgv);
 
         // if the current argument of the current function has ${ARGV in it
         // then try replacing ARGV values
@@ -163,8 +161,8 @@ bool cmMacroHelperCommand::InvokeInitialPass
           {
           for (unsigned int t = 0; t < expandedArgs.size(); ++t)
             {
-            cmSystemTools::ReplaceString(arg.Value, argVs[t].c_str(),
-                                         expandedArgs[t].c_str());
+            cmSystemTools::ReplaceString(arg.Value, argVs[t],
+                                         expandedArgs[t]);
             }
           }
         }
-- 
GitLab