diff options
author | Pavel Solodovnikov <pa.solodovnikov@tensor.ru> | 2018-01-25 13:59:33 (GMT) |
---|---|---|
committer | Pavel Solodovnikov <pa.solodovnikov@tensor.ru> | 2018-01-26 10:24:45 (GMT) |
commit | c85bb007df37aad9f20355cdf4d7ca9af562cb20 (patch) | |
tree | 97027a278ef535cbb277ae91aa4c2eb620cb6978 /Source/CTest | |
parent | fa3ac83af0edf958d26b246109db6e3d6d128d70 (diff) | |
download | CMake-c85bb007df37aad9f20355cdf4d7ca9af562cb20.zip CMake-c85bb007df37aad9f20355cdf4d7ca9af562cb20.tar.gz CMake-c85bb007df37aad9f20355cdf4d7ca9af562cb20.tar.bz2 |
Reduce allocation of temporary values on heap.
- Use `std::move` while inserting temporary results into vectors.
- Change `push_back` to `emplace_back` where appropriate.
Diffstat (limited to 'Source/CTest')
-rw-r--r-- | Source/CTest/cmCTestBuildAndTestHandler.cxx | 15 | ||||
-rw-r--r-- | Source/CTest/cmCTestBuildHandler.cxx | 9 | ||||
-rw-r--r-- | Source/CTest/cmCTestLaunch.cxx | 2 | ||||
-rw-r--r-- | Source/CTest/cmCTestMemCheckHandler.cxx | 15 | ||||
-rw-r--r-- | Source/CTest/cmCTestMultiProcessHandler.cxx | 4 | ||||
-rw-r--r-- | Source/CTest/cmCTestSVN.cxx | 4 | ||||
-rw-r--r-- | Source/CTest/cmCTestTestHandler.cxx | 12 |
7 files changed, 25 insertions, 36 deletions
diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx index 85d98d0..bbb4871 100644 --- a/Source/CTest/cmCTestBuildAndTestHandler.cxx +++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx @@ -51,19 +51,13 @@ int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring, args.push_back(cmSystemTools::GetCMakeCommand()); args.push_back(this->SourceDir); if (!this->BuildGenerator.empty()) { - std::string generator = "-G"; - generator += this->BuildGenerator; - args.push_back(generator); + args.push_back("-G" + this->BuildGenerator); } if (!this->BuildGeneratorPlatform.empty()) { - std::string platform = "-A"; - platform += this->BuildGeneratorPlatform; - args.push_back(platform); + args.push_back("-A" + this->BuildGeneratorPlatform); } if (!this->BuildGeneratorToolset.empty()) { - std::string toolset = "-T"; - toolset += this->BuildGeneratorToolset; - args.push_back(toolset); + args.push_back("-T" + this->BuildGeneratorToolset); } const char* config = nullptr; @@ -77,8 +71,7 @@ int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring, #endif if (config) { - std::string btype = "-DCMAKE_BUILD_TYPE:STRING=" + std::string(config); - args.push_back(btype); + args.push_back("-DCMAKE_BUILD_TYPE:STRING=" + std::string(config)); } for (std::string const& opt : this->BuildOptions) { diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index ef4d3c6..dbbe131 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -17,6 +17,7 @@ #include <set> #include <stdlib.h> #include <string.h> +#include <utility> static const char* cmCTestErrorMatches[] = { "^[Bb]us [Ee]rror", @@ -294,7 +295,7 @@ int cmCTestBuildHandler::ProcessHandler() cmCTestWarningErrorFileLine[entry].RegularExpressionString)) { r.FileIndex = cmCTestWarningErrorFileLine[entry].FileIndex; r.LineIndex = cmCTestWarningErrorFileLine[entry].LineIndex; - this->ErrorWarningFileLineRegex.push_back(r); + this->ErrorWarningFileLineRegex.push_back(std::move(r)); } else { cmCTestLog( this->CTest, ERROR_MESSAGE, "Problem Compiling regular expression: " @@ -894,7 +895,7 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal, errorwarning.PreContext.clear(); errorwarning.PostContext.clear(); errorwarning.Error = false; - this->ErrorsAndWarnings.push_back(errorwarning); + this->ErrorsAndWarnings.push_back(std::move(errorwarning)); this->TotalWarnings++; } } @@ -917,7 +918,7 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal, errorwarning.PreContext.clear(); errorwarning.PostContext.clear(); errorwarning.Error = true; - this->ErrorsAndWarnings.push_back(errorwarning); + this->ErrorsAndWarnings.push_back(std::move(errorwarning)); this->TotalErrors++; cmCTestLog(this->CTest, ERROR_MESSAGE, "There was an error: " << cmsysProcess_GetErrorString(cp) << std::endl); @@ -1009,7 +1010,7 @@ void cmCTestBuildHandler::ProcessBuffer(const char* data, size_t length, this->PreContext.clear(); // Store report - this->ErrorsAndWarnings.push_back(errorwarning); + this->ErrorsAndWarnings.push_back(std::move(errorwarning)); this->LastErrorOrWarning = this->ErrorsAndWarnings.end() - 1; this->PostContextCount = 0; } else { diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx index a1249f5..07dd2f5 100644 --- a/Source/CTest/cmCTestLaunch.cxx +++ b/Source/CTest/cmCTestLaunch.cxx @@ -564,7 +564,7 @@ void cmCTestLaunch::LoadScrapeRules( std::string line; cmsys::RegularExpression rex; while (cmSystemTools::GetLineFromStream(fin, line)) { - if (rex.compile(line.c_str())) { + if (rex.compile(line)) { regexps.push_back(rex); } } diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx index 6b6c337..a6e318a 100644 --- a/Source/CTest/cmCTestMemCheckHandler.cxx +++ b/Source/CTest/cmCTestMemCheckHandler.cxx @@ -14,6 +14,7 @@ #include <iostream> #include <sstream> #include <string.h> +#include <utility> struct CatToErrorType { @@ -545,12 +546,12 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking() << std::endl); return false; } - std::string suppressions = "--suppressions=" + - this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile"); - this->MemoryTesterOptions.push_back(suppressions); + this->MemoryTesterOptions.push_back( + "--suppressions=" + + this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile")); } - std::string outputFile = "--log-file=" + this->MemoryTesterOutputFile; - this->MemoryTesterDynamicOptions.push_back(outputFile); + this->MemoryTesterDynamicOptions.push_back("--log-file=" + + this->MemoryTesterOutputFile); break; } case cmCTestMemCheckHandler::PURIFY: { @@ -588,7 +589,7 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking() "/Testing/Temporary/MemoryChecker.??.DPbd"; this->BoundsCheckerDPBDFile = dpbdFile; this->MemoryTesterDynamicOptions.push_back("/B"); - this->MemoryTesterDynamicOptions.push_back(dpbdFile); + this->MemoryTesterDynamicOptions.push_back(std::move(dpbdFile)); this->MemoryTesterDynamicOptions.push_back("/X"); this->MemoryTesterDynamicOptions.push_back(this->MemoryTesterOutputFile); this->MemoryTesterOptions.push_back("/M"); @@ -1098,5 +1099,5 @@ void cmCTestMemCheckHandler::TestOutputFileNames( cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl); ofile.clear(); } - files.push_back(ofile); + files.push_back(std::move(ofile)); } diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx index 53c47a2..74ac97e 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.cxx +++ b/Source/CTest/cmCTestMultiProcessHandler.cxx @@ -570,7 +570,7 @@ void cmCTestMultiProcessHandler::CreateParallelTestCostList() TestSet alreadySortedTests; std::list<TestSet> priorityStack; - priorityStack.push_back(TestSet()); + priorityStack.emplace_back(); TestSet& topLevel = priorityStack.back(); // In parallel test runs add previously failed tests to the front @@ -592,7 +592,7 @@ void cmCTestMultiProcessHandler::CreateParallelTestCostList() // further dependencies exist. while (!priorityStack.back().empty()) { TestSet& previousSet = priorityStack.back(); - priorityStack.push_back(TestSet()); + priorityStack.emplace_back(); TestSet& currentSet = priorityStack.back(); for (auto const& i : previousSet) { diff --git a/Source/CTest/cmCTestSVN.cxx b/Source/CTest/cmCTestSVN.cxx index ce96224..73184fc 100644 --- a/Source/CTest/cmCTestSVN.cxx +++ b/Source/CTest/cmCTestSVN.cxx @@ -515,7 +515,7 @@ private: } else { local_path = path; } - this->SVN->Repositories.push_back(SVNInfo(local_path.c_str())); + this->SVN->Repositories.emplace_back(local_path.c_str()); } }; @@ -526,7 +526,7 @@ bool cmCTestSVN::LoadRepositories() } // Info for root repository - this->Repositories.push_back(SVNInfo("")); + this->Repositories.emplace_back(""); this->RootInfo = &(this->Repositories.back()); // Run "svn status" to get the list of external repositories diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 4c7cefb..0141a1c 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -2156,9 +2156,7 @@ bool cmCTestTestHandler::SetTestsProperties( std::vector<std::string> lval; cmSystemTools::ExpandListArgument(val, lval); for (std::string const& cr : lval) { - rt.ErrorRegularExpressions.push_back( - std::pair<cmsys::RegularExpression, std::string>( - cmsys::RegularExpression(cr.c_str()), std::string(cr))); + rt.ErrorRegularExpressions.emplace_back(cr, cr); } } if (key == "PROCESSORS") { @@ -2204,9 +2202,7 @@ bool cmCTestTestHandler::SetTestsProperties( std::vector<std::string> lval; cmSystemTools::ExpandListArgument(val, lval); for (std::string const& cr : lval) { - rt.RequiredRegularExpressions.push_back( - std::pair<cmsys::RegularExpression, std::string>( - cmsys::RegularExpression(cr.c_str()), std::string(cr))); + rt.RequiredRegularExpressions.emplace_back(cr, cr); } } if (key == "WORKING_DIRECTORY") { @@ -2225,9 +2221,7 @@ bool cmCTestTestHandler::SetTestsProperties( std::vector<std::string> lval; cmSystemTools::ExpandListArgument(propArgs[1], lval); for (std::string const& cr : lval) { - rt.TimeoutRegularExpressions.push_back( - std::pair<cmsys::RegularExpression, std::string>( - cmsys::RegularExpression(cr.c_str()), std::string(cr))); + rt.TimeoutRegularExpressions.emplace_back(cr, cr); } } } |