From 5c3f188beffb972571a011478ad5a28e89a186a3 Mon Sep 17 00:00:00 2001 From: Clemens Wasser Date: Tue, 25 Jan 2022 21:39:49 +0100 Subject: GlobalNinjaGenerator: Add EncodeLiteralInplace which doesn't copy --- Source/cmGlobalNinjaGenerator.cxx | 16 ++++++++++------ Source/cmGlobalNinjaGenerator.h | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 19c4ee3..8fb0d1d 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -166,14 +166,18 @@ std::string cmGlobalNinjaGenerator::EncodeRuleName(std::string const& name) std::string cmGlobalNinjaGenerator::EncodeLiteral(const std::string& lit) { std::string result = lit; - cmSystemTools::ReplaceString(result, "$", "$$"); - cmSystemTools::ReplaceString(result, "\n", "$\n"); + EncodeLiteralInplace(result); + return result; +} + +void cmGlobalNinjaGenerator::EncodeLiteralInplace(std::string& lit) +{ + cmSystemTools::ReplaceString(lit, "$", "$$"); + cmSystemTools::ReplaceString(lit, "\n", "$\n"); if (this->IsMultiConfig()) { - cmSystemTools::ReplaceString(result, - cmStrCat('$', this->GetCMakeCFGIntDir()), + cmSystemTools::ReplaceString(lit, cmStrCat('$', this->GetCMakeCFGIntDir()), this->GetCMakeCFGIntDir()); } - return result; } std::string cmGlobalNinjaGenerator::EncodePath(const std::string& path) @@ -185,7 +189,7 @@ std::string cmGlobalNinjaGenerator::EncodePath(const std::string& path) else std::replace(result.begin(), result.end(), '/', '\\'); #endif - result = this->EncodeLiteral(result); + this->EncodeLiteralInplace(result); cmSystemTools::ReplaceString(result, " ", "$ "); cmSystemTools::ReplaceString(result, ":", "$:"); return result; diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 84fc06c..ac66944 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -77,6 +77,7 @@ public: static std::string EncodeRuleName(std::string const& name); std::string EncodeLiteral(const std::string& lit); + void EncodeLiteralInplace(std::string& lit); std::string EncodePath(const std::string& path); std::unique_ptr CreateLinkLineComputer( -- cgit v0.12