Commit 18b0330b authored by Sebastian Holtermann's avatar Sebastian Holtermann
Browse files

clang-tidy: Enable performance-inefficient-string-concatenation

Enables the clang-tidy test performance-inefficient-string-concatenation
and replaces all inefficient string concatenations with `cmStrCat`.

Closes: #19555
parent 2327cc0e
......@@ -22,7 +22,6 @@ modernize-*,\
-modernize-use-transparent-functors,\
-modernize-use-using,\
performance-*,\
-performance-inefficient-string-concatenation,\
readability-*,\
-readability-function-size,\
-readability-identifier-naming,\
......
......@@ -385,11 +385,8 @@ int cmCTestBuildHandler::ProcessHandler()
if (this->CTest->GetCTestConfiguration("SourceDirectory").size() > 20) {
std::string srcdir =
this->CTest->GetCTestConfiguration("SourceDirectory") + "/";
std::string srcdirrep;
for (cc = srcdir.size() - 2; cc > 0; cc--) {
if (srcdir[cc] == '/') {
srcdirrep = srcdir.substr(cc);
srcdirrep = "/..." + srcdirrep;
srcdir = srcdir.substr(0, cc + 1);
break;
}
......@@ -399,11 +396,8 @@ int cmCTestBuildHandler::ProcessHandler()
if (this->CTest->GetCTestConfiguration("BuildDirectory").size() > 20) {
std::string bindir =
this->CTest->GetCTestConfiguration("BuildDirectory") + "/";
std::string bindirrep;
for (cc = bindir.size() - 2; cc > 0; cc--) {
if (bindir[cc] == '/') {
bindirrep = bindir.substr(cc);
bindirrep = "/..." + bindirrep;
bindir = bindir.substr(0, cc + 1);
break;
}
......
......@@ -494,9 +494,9 @@ void cmCTestLaunch::DumpFileToXML(cmXMLElement& e3, const char* tag,
continue;
}
if (this->Match(line, this->RegexWarningSuppress)) {
line = "[CTest: warning suppressed] " + line;
line = cmStrCat("[CTest: warning suppressed] ", line);
} else if (this->Match(line, this->RegexWarning)) {
line = "[CTest: warning matched] " + line;
line = cmStrCat("[CTest: warning matched] ", line);
}
e4.Content(sep);
e4.Content(line);
......
......@@ -30,6 +30,7 @@
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmStateSnapshot.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmake.h"
......@@ -663,8 +664,8 @@ int cmCTestScriptHandler::PerformExtraUpdates()
fullCommand, &output, &output, &retVal, cvsArgs[0].c_str(),
this->HandlerVerbose, cmDuration::zero() /*this->TimeOut*/);
if (!res || retVal != 0) {
cmSystemTools::Error("Unable to perform extra updates:\n" + eu +
"\nWith output:\n" + output);
cmSystemTools::Error(cmStrCat("Unable to perform extra updates:\n", eu,
"\nWith output:\n", output));
return 0;
}
}
......@@ -934,7 +935,7 @@ bool cmCTestScriptHandler::TryToRemoveBinaryDirectoryOnce(
continue;
}
std::string fullPath = directoryPath + std::string("/") + path;
std::string fullPath = cmStrCat(directoryPath, "/", path);
bool isDirectory = cmSystemTools::FileIsDirectory(fullPath) &&
!cmSystemTools::FileIsSymlink(fullPath);
......
......@@ -225,7 +225,7 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(
std::string local_file = file;
bool initialize_cdash_buildid = false;
if (!cmSystemTools::FileExists(local_file)) {
local_file = localprefix + "/" + file;
local_file = cmStrCat(localprefix, "/", file);
// If this file exists within the local Testing directory we assume
// that it will be associated with the current build in CDash.
initialize_cdash_buildid = true;
......@@ -237,9 +237,9 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(
<< remote_file << std::endl;
std::string ofile = cmSystemTools::EncodeURL(remote_file);
std::string upload_as = url +
((url.find('?') == std::string::npos) ? '?' : '&') +
"FileName=" + ofile;
std::string upload_as =
cmStrCat(url, ((url.find('?') == std::string::npos) ? '?' : '&'),
"FileName=", ofile);
if (initialize_cdash_buildid) {
// Provide extra arguments to CDash so that it can initialize and
......
......@@ -2,6 +2,7 @@
#include "cmCTest.h"
#include "cmCTestCoverageHandler.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmXMLParser.h"
......@@ -75,7 +76,7 @@ protected:
// Check if this is a path that is relative to our source or
// binary directories.
for (std::string const& filePath : FilePaths) {
finalpath = filePath + "/" + filename;
finalpath = cmStrCat(filePath, "/", filename);
if (cmSystemTools::FileExists(finalpath)) {
this->CurFileName = finalpath;
break;
......@@ -86,7 +87,7 @@ protected:
cmsys::ifstream fin(this->CurFileName.c_str());
if (this->CurFileName.empty() || !fin) {
this->CurFileName =
this->Coverage.BinaryDir + "/" + atts[tagCount + 1];
cmStrCat(this->Coverage.BinaryDir, "/", atts[tagCount + 1]);
fin.open(this->CurFileName.c_str());
if (!fin) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
......
......@@ -8,6 +8,7 @@
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmRuntimeDependencyArchive.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include <cmsys/RegularExpression.hxx>
......@@ -151,7 +152,7 @@ bool cmBinUtilsLinuxELFLinker::ResolveDependency(
std::string& path, bool& resolved)
{
for (auto const& searchPath : searchPaths) {
path = searchPath + '/' + name;
path = cmStrCat(searchPath, '/', name);
if (cmSystemTools::PathExists(path)) {
resolved = true;
return true;
......@@ -159,7 +160,7 @@ bool cmBinUtilsLinuxELFLinker::ResolveDependency(
}
for (auto const& searchPath : this->Archive->GetSearchDirectories()) {
path = searchPath + '/' + name;
path = cmStrCat(searchPath, '/', name);
if (cmSystemTools::PathExists(path)) {
std::ostringstream warning;
warning << "Dependency " << name << " found in search directory:\n "
......
......@@ -6,6 +6,7 @@
#include "cmBinUtilsWindowsPEDumpbinGetRuntimeDependenciesTool.h"
#include "cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool.h"
#include "cmRuntimeDependencyArchive.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include <sstream>
......@@ -110,7 +111,7 @@ bool cmBinUtilsWindowsPELinker::ResolveDependency(std::string const& name,
dirs.insert(dirs.begin(), origin);
for (auto const& searchPath : dirs) {
path = searchPath + '/' + name;
path = cmStrCat(searchPath, '/', name);
if (cmSystemTools::PathExists(path)) {
resolved = true;
return true;
......
......@@ -1754,7 +1754,7 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs,
cmSystemTools::IsSubDirectory(d, topBinaryDir)) {
d = cmSystemTools::RelativePath(targetOutputDir, d);
if (!d.empty()) {
d = originToken + "/" + d;
d = cmStrCat(originToken, "/", d);
} else {
d = originToken;
}
......
......@@ -514,7 +514,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
for (std::string const& li : testLangs) {
projectLangs += " " + li;
std::string rulesOverrideBase = "CMAKE_USER_MAKE_RULES_OVERRIDE";
std::string rulesOverrideLang = rulesOverrideBase + "_" + li;
std::string rulesOverrideLang = cmStrCat(rulesOverrideBase, "_", li);
if (const char* rulesOverridePath =
this->Makefile->GetDefinition(rulesOverrideLang)) {
fprintf(fout, "set(%s \"%s\")\n", rulesOverrideLang.c_str(),
......@@ -574,7 +574,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
std::string const cfg =
!tcConfig.empty() ? cmSystemTools::UpperCase(tcConfig) : cfgDefault;
for (std::string const& li : testLangs) {
std::string const langFlagsCfg = "CMAKE_" + li + "_FLAGS_" + cfg;
std::string const langFlagsCfg =
cmStrCat("CMAKE_", li, "_FLAGS_", cfg);
const char* flagsCfg = this->Makefile->GetDefinition(langFlagsCfg);
fprintf(fout, "set(%s %s)\n", langFlagsCfg.c_str(),
cmOutputConverter::EscapeForCMake(flagsCfg ? flagsCfg : "")
......
......@@ -412,7 +412,7 @@ void cmExportInstallFileGenerator::SetImportLocationProperty(
std::vector<std::string> objects;
itgen->GetInstallObjectNames(config, objects);
for (std::string& obj : objects) {
obj = value + obj;
obj = cmStrCat(value, obj);
}
// Store the property.
......
......@@ -16,6 +16,7 @@
#include "cmRange.h"
#include "cmSourceFile.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmXMLWriter.h"
#include "cmake.h"
......@@ -178,18 +179,18 @@ void Tree::BuildUnitImpl(cmXMLWriter& xml,
{
for (std::string const& f : files) {
xml.StartElement("Unit");
xml.Attribute("filename", fsPath + path + "/" + f);
xml.Attribute("filename", cmStrCat(fsPath, path, "/", f));
xml.StartElement("Option");
xml.Attribute("virtualFolder",
"CMake Files\\" + virtualFolderPath + path + "\\");
cmStrCat("CMake Files\\", virtualFolderPath, path, "\\"));
xml.EndElement();
xml.EndElement();
}
for (Tree const& folder : folders) {
folder.BuildUnitImpl(xml, virtualFolderPath + path + "\\",
fsPath + path + "/");
folder.BuildUnitImpl(xml, cmStrCat(virtualFolderPath, path, "\\"),
cmStrCat(fsPath, path, "/"));
}
}
......
......@@ -9,6 +9,7 @@
#include "cmMakefile.h"
#include "cmSourceFile.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmXMLWriter.h"
#include "cmake.h"
......@@ -121,7 +122,7 @@ std::vector<std::string> cmExtraCodeLiteGenerator::CreateProjectsByTarget(
cmStateEnums::TargetType type = lt->GetType();
std::string const& outputDir = lg->GetCurrentBinaryDirectory();
std::string targetName = lt->GetName();
std::string filename = outputDir + "/" + targetName + ".project";
std::string filename = cmStrCat(outputDir, "/", targetName, ".project");
retval.push_back(targetName);
// Make the project file relative to the workspace
std::string relafilename =
......@@ -131,7 +132,7 @@ std::vector<std::string> cmExtraCodeLiteGenerator::CreateProjectsByTarget(
case cmStateEnums::SHARED_LIBRARY:
case cmStateEnums::STATIC_LIBRARY:
case cmStateEnums::MODULE_LIBRARY:
visualname = "lib" + visualname;
visualname = cmStrCat("lib", visualname);
CM_FALLTHROUGH;
case cmStateEnums::EXECUTABLE:
xml->StartElement("Project");
......@@ -161,7 +162,7 @@ std::vector<std::string> cmExtraCodeLiteGenerator::CreateProjectsByProjectMaps(
std::string const& outputDir = it.second[0]->GetCurrentBinaryDirectory();
std::string projectName = it.second[0]->GetProjectName();
retval.push_back(projectName);
std::string filename = outputDir + "/" + projectName + ".project";
std::string filename = cmStrCat(outputDir, "/", projectName, ".project");
// Make the project file relative to the workspace
filename = cmSystemTools::RelativePath(this->WorkspacePath, filename);
......
......@@ -17,6 +17,7 @@
#include "cmMessageType.h"
#include "cmSourceFile.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmake.h"
......@@ -266,7 +267,7 @@ void cmExtraSublimeTextGenerator::AppendTarget(
R"((^|[ ])-[DIOUWfgs][^= ]+(=\"[^"]+\"|=[^"][^ ]+)?)";
flagRegex.compile(regexString);
std::string workString =
flagsString + " " + definesString + " " + includesString;
cmStrCat(flagsString, " ", definesString, " ", includesString);
while (flagRegex.find(workString)) {
std::string::size_type start = flagRegex.start();
if (workString[start] == ' ') {
......
......@@ -8,6 +8,7 @@
#include "cmMakefile.h"
#include "cmRange.h"
#include "cmSourceFile.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
class cmExecutionStatus;
......@@ -66,18 +67,15 @@ bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args,
// if we should use the source GUI
// to generate .cxx and .h files
if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE")) {
std::string outName = outputDirectory;
outName += "/";
outName += cmSystemTools::GetFilenameWithoutExtension(arg);
std::string hname = outName;
hname += ".h";
std::string origname = cdir + "/" + arg;
std::string outName = cmStrCat(
outputDirectory, "/", cmSystemTools::GetFilenameWithoutExtension(arg));
std::string hname = cmStrCat(outName, ".h");
std::string origname = cmStrCat(cdir, "/", arg);
// add starting depends
std::vector<std::string> depends;
depends.push_back(origname);
depends.push_back(fluid_exe);
std::string cxxres = outName;
cxxres += ".cxx";
std::string cxxres = cmStrCat(outName, ".cxx");
cmCustomCommandLine commandLine;
commandLine.push_back(fluid_exe);
......
......@@ -94,7 +94,7 @@ void cmFileAPI::RemoveOldReplyFiles()
std::vector<std::string> files = this->LoadDir(reply_dir);
for (std::string const& f : files) {
if (this->ReplyFiles.find(f) == this->ReplyFiles.end()) {
std::string file = reply_dir + "/" + f;
std::string file = cmStrCat(reply_dir, "/", f);
cmSystemTools::RemoveFile(file);
}
}
......
......@@ -7,6 +7,7 @@
#include "cmFileCommand.h"
#include "cmFileTimes.h"
#include "cmMakefile.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmsys/Directory.hxx"
#include "cmsys/Glob.hxx"
......@@ -490,7 +491,7 @@ bool cmFileCopier::InstallSymlinkChain(std::string& fromFile,
while (cmSystemTools::ReadSymlink(fromFile, newFromFile)) {
if (!cmSystemTools::FileIsFullPath(newFromFile)) {
std::string fromFilePath = cmSystemTools::GetFilenamePath(fromFile);
newFromFile = fromFilePath + "/" + newFromFile;
newFromFile = cmStrCat(fromFilePath, "/", newFromFile);
}
std::string symlinkTarget = cmSystemTools::GetFilenameName(newFromFile);
......@@ -520,7 +521,7 @@ bool cmFileCopier::InstallSymlinkChain(std::string& fromFile,
}
fromFile = newFromFile;
toFile = toFilePath + "/" + symlinkTarget;
toFile = cmStrCat(toFilePath, "/", symlinkTarget);
}
return true;
......
......@@ -1441,7 +1441,7 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode
}
for (std::string& o : objects) {
o = obj_dir + o;
o = cmStrCat(obj_dir, o);
}
}
......
......@@ -18,6 +18,7 @@
#include "cmStateDirectory.h"
#include "cmStateSnapshot.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
......@@ -442,12 +443,12 @@ void cmGhsMultiTargetGenerator::WriteCustomCommandsHelper(
// This command was specified as a path to a file in the
// current directory. Add a leading "./" so it can run
// without the current directory being in the search path.
cmd = "./" + cmd;
cmd = cmStrCat("./", cmd);
}
cmd = this->LocalGenerator->ConvertToOutputFormat(
cmd, cmOutputConverter::SHELL);
if (useCall) {
cmd = "call " + cmd;
cmd = cmStrCat("call ", cmd);
}
ccg.AppendArguments(c, cmd);
cmdLines.push_back(std::move(cmd));
......
......@@ -11,6 +11,7 @@
#include "cmMakefile.h"
#include "cmState.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmVersion.h"
#include "cmake.h"
......@@ -418,17 +419,17 @@ void cmGlobalGhsMultiGenerator::WriteTargets(cmLocalGenerator* root)
}
// create target build file
std::string name = target->GetName() + ".tgt" + FILE_EXTENSION;
std::string fname = rootBinaryDir + "/" + name;
std::string name = cmStrCat(target->GetName(), ".tgt", FILE_EXTENSION);
std::string fname = cmStrCat(rootBinaryDir, "/", name);
cmGeneratedFileStream fbld(fname);
fbld.SetCopyIfDifferent(true);
this->WriteFileHeader(fbld);
GhsMultiGpj::WriteGpjTag(GhsMultiGpj::PROJECT, fbld);
std::vector<cmGeneratorTarget const*> build;
if (ComputeTargetBuildOrder(target, build)) {
std::string message = "The inter-target dependency graph for target [" +
target->GetName() + "] had a cycle.\n";
cmSystemTools::Error(message);
cmSystemTools::Error(
cmStrCat("The inter-target dependency graph for target [",
target->GetName(), "] had a cycle.\n"));
} else {
for (auto& tgt : build) {
WriteProjectLine(fbld, tgt, root, rootBinaryDir);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment