Source: remove useless copies & reallocations

This commit is contained in:
AJIOB
2026-07-08 09:40:54 -04:00
committed by Brad King
parent 1482795668
commit b3dd0aa7c8
3 changed files with 76 additions and 73 deletions
+30 -28
View File
@@ -1042,28 +1042,29 @@ void cmGlobalFastbuildGenerator::AddCompiler(std::string const& language,
if (cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER_EQUAL,
compilerDef.CmakeCompilerVersion,
"19.20")) {
compilerDef.ExtraFiles.push_back("$Root$/c1.dll");
compilerDef.ExtraFiles.push_back("$Root$/c1xx.dll");
compilerDef.ExtraFiles.push_back("$Root$/c2.dll");
compilerDef.ExtraFiles.push_back(
compilerDef.ExtraFiles.reserve(compilerDef.ExtraFiles.size() + 16);
compilerDef.ExtraFiles.emplace_back("$Root$/c1.dll");
compilerDef.ExtraFiles.emplace_back("$Root$/c1xx.dll");
compilerDef.ExtraFiles.emplace_back("$Root$/c2.dll");
compilerDef.ExtraFiles.emplace_back(
"$Root$/atlprov.dll"); // Only needed if using ATL
compilerDef.ExtraFiles.push_back("$Root$/msobj140.dll");
compilerDef.ExtraFiles.push_back("$Root$/mspdb140.dll");
compilerDef.ExtraFiles.push_back("$Root$/mspdbcore.dll");
compilerDef.ExtraFiles.push_back("$Root$/mspdbsrv.exe");
compilerDef.ExtraFiles.push_back("$Root$/mspft140.dll");
compilerDef.ExtraFiles.push_back("$Root$/msvcp140.dll");
compilerDef.ExtraFiles.push_back(
compilerDef.ExtraFiles.emplace_back("$Root$/msobj140.dll");
compilerDef.ExtraFiles.emplace_back("$Root$/mspdb140.dll");
compilerDef.ExtraFiles.emplace_back("$Root$/mspdbcore.dll");
compilerDef.ExtraFiles.emplace_back("$Root$/mspdbsrv.exe");
compilerDef.ExtraFiles.emplace_back("$Root$/mspft140.dll");
compilerDef.ExtraFiles.emplace_back("$Root$/msvcp140.dll");
compilerDef.ExtraFiles.emplace_back(
"$Root$/msvcp140_atomic_wait.dll"); // Required circa 16.8.3
// (14.28.29333)
compilerDef.ExtraFiles.push_back(
compilerDef.ExtraFiles.emplace_back(
"$Root$/tbbmalloc.dll"); // Required as of 16.2 (14.22.27905)
compilerDef.ExtraFiles.push_back("$Root$/vcruntime140.dll");
compilerDef.ExtraFiles.push_back(
compilerDef.ExtraFiles.emplace_back("$Root$/vcruntime140.dll");
compilerDef.ExtraFiles.emplace_back(
"$Root$/vcruntime140_1.dll"); // Required as of 16.5.1 (14.25.28610)
compilerDef.ExtraFiles.push_back(
compilerDef.ExtraFiles.emplace_back(
cmStrCat("$Root$/", i18nNum, "/clui.dll"));
compilerDef.ExtraFiles.push_back(cmStrCat(
compilerDef.ExtraFiles.emplace_back(cmStrCat(
"$Root$/", i18nNum, "/mspft140ui.dll")); // Localized messages for
// static analysis
}
@@ -1071,19 +1072,20 @@ void cmGlobalFastbuildGenerator::AddCompiler(std::string const& language,
else if (cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER_EQUAL,
compilerDef.CmakeCompilerVersion,
"19.10")) {
compilerDef.ExtraFiles.push_back("$Root$/c1.dll");
compilerDef.ExtraFiles.push_back("$Root$/c1xx.dll");
compilerDef.ExtraFiles.push_back("$Root$/c2.dll");
compilerDef.ExtraFiles.push_back(
compilerDef.ExtraFiles.reserve(compilerDef.ExtraFiles.size() + 12);
compilerDef.ExtraFiles.emplace_back("$Root$/c1.dll");
compilerDef.ExtraFiles.emplace_back("$Root$/c1xx.dll");
compilerDef.ExtraFiles.emplace_back("$Root$/c2.dll");
compilerDef.ExtraFiles.emplace_back(
"$Root$/atlprov.dll"); // Only needed if using ATL
compilerDef.ExtraFiles.push_back("$Root$/msobj140.dll");
compilerDef.ExtraFiles.push_back("$Root$/mspdb140.dll");
compilerDef.ExtraFiles.push_back("$Root$/mspdbcore.dll");
compilerDef.ExtraFiles.push_back("$Root$/mspdbsrv.exe");
compilerDef.ExtraFiles.push_back("$Root$/mspft140.dll");
compilerDef.ExtraFiles.push_back("$Root$/msvcp140.dll");
compilerDef.ExtraFiles.push_back("$Root$/vcruntime140.dll");
compilerDef.ExtraFiles.push_back("$Root$/" + i18nNum + "/clui.dll");
compilerDef.ExtraFiles.emplace_back("$Root$/msobj140.dll");
compilerDef.ExtraFiles.emplace_back("$Root$/mspdb140.dll");
compilerDef.ExtraFiles.emplace_back("$Root$/mspdbcore.dll");
compilerDef.ExtraFiles.emplace_back("$Root$/mspdbsrv.exe");
compilerDef.ExtraFiles.emplace_back("$Root$/mspft140.dll");
compilerDef.ExtraFiles.emplace_back("$Root$/msvcp140.dll");
compilerDef.ExtraFiles.emplace_back("$Root$/vcruntime140.dll");
compilerDef.ExtraFiles.emplace_back("$Root$/" + i18nNum + "/clui.dll");
}
}
// TODO: Handle Intel compiler
+42 -42
View File
@@ -3167,14 +3167,14 @@ void cmGlobalGenerator::AddGlobalTarget_Package(
gti.UsesTerminal = true;
gti.WorkingDir = mf->GetCurrentBinaryDirectory();
cmCustomCommandLine singleLine;
singleLine.push_back(cmSystemTools::GetCPackCommand());
singleLine.emplace_back(cmSystemTools::GetCPackCommand());
if (cmNonempty(cmakeCfgIntDir) && cmakeCfgIntDir[0] != '.') {
singleLine.push_back("-C");
singleLine.push_back(cmakeCfgIntDir);
singleLine.emplace_back("-C");
singleLine.emplace_back(cmakeCfgIntDir);
}
singleLine.push_back("--config");
singleLine.push_back("./CPackConfig.cmake");
gti.CommandLines.push_back(std::move(singleLine));
singleLine.emplace_back("--config");
singleLine.emplace_back("./CPackConfig.cmake");
gti.CommandLines.emplace_back(std::move(singleLine));
if (this->GetPreinstallTargetName()) {
gti.Depends.emplace_back(this->GetPreinstallTargetName());
} else {
@@ -3184,7 +3184,7 @@ void cmGlobalGenerator::AddGlobalTarget_Package(
gti.Depends.emplace_back(this->GetAllTargetName());
}
}
targets.push_back(std::move(gti));
targets.emplace_back(std::move(gti));
}
void cmGlobalGenerator::AddGlobalTarget_PackageSource(
@@ -3216,11 +3216,11 @@ void cmGlobalGenerator::AddGlobalTarget_PackageSource(
gti.WorkingDir = mf->GetCurrentBinaryDirectory();
gti.UsesTerminal = true;
cmCustomCommandLine singleLine;
singleLine.push_back(cmSystemTools::GetCPackCommand());
singleLine.push_back("--config");
singleLine.push_back("./CPackSourceConfig.cmake");
gti.CommandLines.push_back(std::move(singleLine));
targets.push_back(std::move(gti));
singleLine.emplace_back(cmSystemTools::GetCPackCommand());
singleLine.emplace_back("--config");
singleLine.emplace_back("./CPackSourceConfig.cmake");
gti.CommandLines.emplace_back(std::move(singleLine));
targets.emplace_back(std::move(gti));
}
void cmGlobalGenerator::AddGlobalTarget_Test(
@@ -3253,21 +3253,21 @@ void cmGlobalGenerator::AddGlobalTarget_Test(
}
}
cmCustomCommandLine singleLine;
singleLine.push_back(cmSystemTools::GetCTestCommand());
singleLine.emplace_back(cmSystemTools::GetCTestCommand());
cmList args(mf->GetDefinition("CMAKE_CTEST_ARGUMENTS"));
for (auto const& arg : args) {
singleLine.push_back(arg);
singleLine.emplace_back(arg);
}
if (cmNonempty(cmakeCfgIntDir) && cmakeCfgIntDir[0] != '.') {
singleLine.push_back("-C");
singleLine.push_back(cmakeCfgIntDir);
singleLine.emplace_back("-C");
singleLine.emplace_back(cmakeCfgIntDir);
} else // TODO: This is a hack. Should be something to do with the
// generator
{
singleLine.push_back("$(ARGS)");
singleLine.emplace_back("$(ARGS)");
}
gti.CommandLines.push_back(std::move(singleLine));
targets.push_back(std::move(gti));
gti.CommandLines.emplace_back(std::move(singleLine));
targets.emplace_back(std::move(gti));
}
void cmGlobalGenerator::ReserveGlobalTargetCodegen()
@@ -3321,29 +3321,29 @@ void cmGlobalGenerator::AddGlobalTarget_EditCache(
// Use generator preference for the edit_cache rule if it is defined.
std::string edit_cmd = this->GetEditCacheCommand();
if (!edit_cmd.empty()) {
singleLine.push_back(std::move(edit_cmd));
singleLine.emplace_back(std::move(edit_cmd));
if (this->GetCMakeInstance()->GetIgnoreCompileWarningAsError()) {
singleLine.push_back("--compile-no-warning-as-error");
singleLine.emplace_back("--compile-no-warning-as-error");
}
if (this->GetCMakeInstance()->GetIgnoreLinkWarningAsError()) {
singleLine.push_back("--link-no-warning-as-error");
singleLine.emplace_back("--link-no-warning-as-error");
}
singleLine.push_back("-S$(CMAKE_SOURCE_DIR)");
singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
singleLine.emplace_back("-S$(CMAKE_SOURCE_DIR)");
singleLine.emplace_back("-B$(CMAKE_BINARY_DIR)");
gti.Message = "Running CMake cache editor...";
gti.UsesTerminal = true;
} else {
singleLine.push_back(cmSystemTools::GetCMakeCommand());
singleLine.push_back("-E");
singleLine.push_back("echo");
singleLine.push_back("No interactive CMake dialog available.");
singleLine.emplace_back(cmSystemTools::GetCMakeCommand());
singleLine.emplace_back("-E");
singleLine.emplace_back("echo");
singleLine.emplace_back("No interactive CMake dialog available.");
gti.Message = "No interactive CMake dialog available...";
gti.UsesTerminal = false;
gti.StdPipesUTF8 = true;
}
gti.CommandLines.push_back(std::move(singleLine));
gti.CommandLines.emplace_back(std::move(singleLine));
targets.push_back(std::move(gti));
targets.emplace_back(std::move(gti));
}
void cmGlobalGenerator::AddGlobalTarget_RebuildCache(
@@ -3359,19 +3359,19 @@ void cmGlobalGenerator::AddGlobalTarget_RebuildCache(
gti.UsesTerminal = true;
gti.PerConfig = cmTarget::PerConfig::No;
cmCustomCommandLine singleLine;
singleLine.push_back(cmSystemTools::GetCMakeCommand());
singleLine.push_back("--regenerate-during-build");
singleLine.emplace_back(cmSystemTools::GetCMakeCommand());
singleLine.emplace_back("--regenerate-during-build");
if (this->GetCMakeInstance()->GetIgnoreCompileWarningAsError()) {
singleLine.push_back("--compile-no-warning-as-error");
singleLine.emplace_back("--compile-no-warning-as-error");
}
if (this->GetCMakeInstance()->GetIgnoreLinkWarningAsError()) {
singleLine.push_back("--link-no-warning-as-error");
singleLine.emplace_back("--link-no-warning-as-error");
}
singleLine.push_back("-S$(CMAKE_SOURCE_DIR)");
singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
gti.CommandLines.push_back(std::move(singleLine));
singleLine.emplace_back("-S$(CMAKE_SOURCE_DIR)");
singleLine.emplace_back("-B$(CMAKE_BINARY_DIR)");
gti.CommandLines.emplace_back(std::move(singleLine));
gti.StdPipesUTF8 = true;
targets.push_back(std::move(gti));
targets.emplace_back(std::move(gti));
}
void cmGlobalGenerator::AddGlobalTarget_Install(
@@ -3438,10 +3438,10 @@ void cmGlobalGenerator::AddGlobalTarget_Install(
}
singleLine.push_back(cfgArg);
}
singleLine.push_back("-P");
singleLine.push_back("cmake_install.cmake");
gti.CommandLines.push_back(singleLine);
targets.push_back(gti);
singleLine.emplace_back("-P");
singleLine.emplace_back("cmake_install.cmake");
gti.CommandLines.emplace_back(singleLine);
targets.emplace_back(gti);
// install_local
if (char const* install_local = this->GetInstallLocalTargetName()) {
+4 -3
View File
@@ -3875,9 +3875,10 @@ int cmake::GetSystemInformation(std::vector<std::string>& args)
return 1;
}
std::vector<std::string> args2;
args2.push_back(args[0]);
args2.push_back(destPath);
args2.push_back("-DRESULT_FILE=" + resultFile);
args2.reserve(3);
args2.emplace_back(args[0]);
args2.emplace_back(destPath);
args2.emplace_back("-DRESULT_FILE=" + resultFile);
int res = this->Run(args2, false);
if (res != 0) {