CTest: avoid repeated string compares

Only one key can match per iteration, avoid any further compares when one match
was already found. While at it entirely avoid that the key and value strings are
copied.
This commit is contained in:
Rolf Eike Beer
2020-03-20 13:59:59 +01:00
parent d1e6ee6fe3
commit d6a4e9fbc8
2 changed files with 90 additions and 132 deletions

View File

@@ -2144,12 +2144,12 @@ bool cmCTestTestHandler::SetTestsProperties(
}
++it; // skip PROPERTIES
for (; it != args.end(); ++it) {
std::string key = *it;
std::string const& key = *it;
++it;
if (it == args.end()) {
break;
}
std::string val = *it;
std::string const& val = *it;
for (std::string const& t : tests) {
for (cmCTestTestProperties& rt : this->TestList) {
if (t == rt.Name) {
@@ -2177,91 +2177,70 @@ bool cmCTestTestHandler::SetTestsProperties(
rt.Backtrace = rt.Backtrace.Push(fc);
}
}
}
if (key == "WILL_FAIL") {
} else if (key == "WILL_FAIL") {
rt.WillFail = cmIsOn(val);
}
if (key == "DISABLED") {
} else if (key == "DISABLED") {
rt.Disabled = cmIsOn(val);
}
if (key == "ATTACHED_FILES") {
} else if (key == "ATTACHED_FILES") {
cmExpandList(val, rt.AttachedFiles);
}
if (key == "ATTACHED_FILES_ON_FAIL") {
} else if (key == "ATTACHED_FILES_ON_FAIL") {
cmExpandList(val, rt.AttachOnFail);
}
if (key == "RESOURCE_LOCK") {
} else if (key == "RESOURCE_LOCK") {
std::vector<std::string> lval = cmExpandedList(val);
rt.LockedResources.insert(lval.begin(), lval.end());
}
if (key == "FIXTURES_SETUP") {
} else if (key == "FIXTURES_SETUP") {
std::vector<std::string> lval = cmExpandedList(val);
rt.FixturesSetup.insert(lval.begin(), lval.end());
}
if (key == "FIXTURES_CLEANUP") {
} else if (key == "FIXTURES_CLEANUP") {
std::vector<std::string> lval = cmExpandedList(val);
rt.FixturesCleanup.insert(lval.begin(), lval.end());
}
if (key == "FIXTURES_REQUIRED") {
} else if (key == "FIXTURES_REQUIRED") {
std::vector<std::string> lval = cmExpandedList(val);
rt.FixturesRequired.insert(lval.begin(), lval.end());
}
if (key == "TIMEOUT") {
} else if (key == "TIMEOUT") {
rt.Timeout = cmDuration(atof(val.c_str()));
rt.ExplicitTimeout = true;
}
if (key == "COST") {
} else if (key == "COST") {
rt.Cost = static_cast<float>(atof(val.c_str()));
}
if (key == "REQUIRED_FILES") {
} else if (key == "REQUIRED_FILES") {
cmExpandList(val, rt.RequiredFiles);
}
if (key == "RUN_SERIAL") {
} else if (key == "RUN_SERIAL") {
rt.RunSerial = cmIsOn(val);
}
if (key == "FAIL_REGULAR_EXPRESSION") {
} else if (key == "FAIL_REGULAR_EXPRESSION") {
std::vector<std::string> lval = cmExpandedList(val);
for (std::string const& cr : lval) {
rt.ErrorRegularExpressions.emplace_back(cr, cr);
}
}
if (key == "SKIP_REGULAR_EXPRESSION") {
} else if (key == "SKIP_REGULAR_EXPRESSION") {
std::vector<std::string> lval = cmExpandedList(val);
for (std::string const& cr : lval) {
rt.SkipRegularExpressions.emplace_back(cr, cr);
}
}
if (key == "PROCESSORS") {
} else if (key == "PROCESSORS") {
rt.Processors = atoi(val.c_str());
if (rt.Processors < 1) {
rt.Processors = 1;
}
}
if (key == "PROCESSOR_AFFINITY") {
} else if (key == "PROCESSOR_AFFINITY") {
rt.WantAffinity = cmIsOn(val);
}
if (key == "RESOURCE_GROUPS") {
} else if (key == "RESOURCE_GROUPS") {
if (!ParseResourceGroupsProperty(val, rt.ResourceGroups)) {
return false;
}
}
if (key == "SKIP_RETURN_CODE") {
} else if (key == "SKIP_RETURN_CODE") {
rt.SkipReturnCode = atoi(val.c_str());
if (rt.SkipReturnCode < 0 || rt.SkipReturnCode > 255) {
rt.SkipReturnCode = -1;
}
}
if (key == "DEPENDS") {
} else if (key == "DEPENDS") {
cmExpandList(val, rt.Depends);
}
if (key == "ENVIRONMENT") {
} else if (key == "ENVIRONMENT") {
cmExpandList(val, rt.Environment);
}
if (key == "LABELS") {
} else if (key == "LABELS") {
std::vector<std::string> Labels = cmExpandedList(val);
rt.Labels.insert(rt.Labels.end(), Labels.begin(), Labels.end());
// sort the array
@@ -2269,8 +2248,7 @@ bool cmCTestTestHandler::SetTestsProperties(
// remove duplicates
auto new_end = std::unique(rt.Labels.begin(), rt.Labels.end());
rt.Labels.erase(new_end, rt.Labels.end());
}
if (key == "MEASUREMENT") {
} else if (key == "MEASUREMENT") {
size_t pos = val.find_first_of('=');
if (pos != std::string::npos) {
std::string mKey = val.substr(0, pos);
@@ -2279,17 +2257,14 @@ bool cmCTestTestHandler::SetTestsProperties(
} else {
rt.Measurements[val] = "1";
}
}
if (key == "PASS_REGULAR_EXPRESSION") {
} else if (key == "PASS_REGULAR_EXPRESSION") {
std::vector<std::string> lval = cmExpandedList(val);
for (std::string const& cr : lval) {
rt.RequiredRegularExpressions.emplace_back(cr, cr);
}
}
if (key == "WORKING_DIRECTORY") {
} else if (key == "WORKING_DIRECTORY") {
rt.Directory = val;
}
if (key == "TIMEOUT_AFTER_MATCH") {
} else if (key == "TIMEOUT_AFTER_MATCH") {
std::vector<std::string> propArgs = cmExpandedList(val);
if (propArgs.size() != 2) {
cmCTestLog(this->CTest, WARNING,

View File

@@ -1828,8 +1828,8 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
std::string arg = args[i];
if (this->CheckArgument(arg, "-F")) {
this->Impl->Failover = true;
}
if (this->CheckArgument(arg, "-j", "--parallel") && i < args.size() - 1) {
} else if (this->CheckArgument(arg, "-j", "--parallel") &&
i < args.size() - 1) {
i++;
int plevel = atoi(args[i].c_str());
this->SetParallelLevel(plevel);
@@ -1840,7 +1840,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
this->Impl->ParallelLevelSetInCli = true;
}
if (this->CheckArgument(arg, "--repeat-until-fail")) {
else if (this->CheckArgument(arg, "--repeat-until-fail")) {
if (i >= args.size() - 1) {
errormsg = "'--repeat-until-fail' requires an argument";
return false;
@@ -1862,7 +1862,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
}
}
if (this->CheckArgument(arg, "--repeat")) {
else if (this->CheckArgument(arg, "--repeat")) {
if (i >= args.size() - 1) {
errormsg = "'--repeat' requires an argument";
return false;
@@ -1895,7 +1895,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
}
}
if (this->CheckArgument(arg, "--test-load") && i < args.size() - 1) {
else if (this->CheckArgument(arg, "--test-load") && i < args.size() - 1) {
i++;
unsigned long load;
if (cmStrToULong(args[i], &load)) {
@@ -1906,76 +1906,66 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
}
}
if (this->CheckArgument(arg, "--no-compress-output")) {
else if (this->CheckArgument(arg, "--no-compress-output")) {
this->Impl->CompressTestOutput = false;
}
if (this->CheckArgument(arg, "--print-labels")) {
else if (this->CheckArgument(arg, "--print-labels")) {
this->Impl->PrintLabels = true;
}
if (this->CheckArgument(arg, "--http1.0")) {
else if (this->CheckArgument(arg, "--http1.0")) {
this->Impl->UseHTTP10 = true;
}
if (this->CheckArgument(arg, "--timeout") && i < args.size() - 1) {
else if (this->CheckArgument(arg, "--timeout") && i < args.size() - 1) {
i++;
auto timeout = cmDuration(atof(args[i].c_str()));
this->Impl->GlobalTimeout = timeout;
}
if (this->CheckArgument(arg, "--stop-time") && i < args.size() - 1) {
else if (this->CheckArgument(arg, "--stop-time") && i < args.size() - 1) {
i++;
this->SetStopTime(args[i]);
}
if (this->CheckArgument(arg, "-C", "--build-config") &&
i < args.size() - 1) {
else if (this->CheckArgument(arg, "-C", "--build-config") &&
i < args.size() - 1) {
i++;
this->SetConfigType(args[i].c_str());
}
if (this->CheckArgument(arg, "--debug")) {
else if (this->CheckArgument(arg, "--debug")) {
this->Impl->Debug = true;
this->Impl->ShowLineNumbers = true;
}
if (this->CheckArgument(arg, "--group") && i < args.size() - 1) {
} else if (this->CheckArgument(arg, "--group") && i < args.size() - 1) {
i++;
this->Impl->SpecificGroup = args[i];
}
// This is an undocumented / deprecated option.
// "Track" has been renamed to "Group".
if (this->CheckArgument(arg, "--track") && i < args.size() - 1) {
else if (this->CheckArgument(arg, "--track") && i < args.size() - 1) {
i++;
this->Impl->SpecificGroup = args[i];
}
if (this->CheckArgument(arg, "--show-line-numbers")) {
} else if (this->CheckArgument(arg, "--show-line-numbers")) {
this->Impl->ShowLineNumbers = true;
}
if (this->CheckArgument(arg, "--no-label-summary")) {
} else if (this->CheckArgument(arg, "--no-label-summary")) {
this->Impl->LabelSummary = false;
}
if (this->CheckArgument(arg, "--no-subproject-summary")) {
} else if (this->CheckArgument(arg, "--no-subproject-summary")) {
this->Impl->SubprojectSummary = false;
}
if (this->CheckArgument(arg, "-Q", "--quiet")) {
} else if (this->CheckArgument(arg, "-Q", "--quiet")) {
this->Impl->Quiet = true;
}
if (this->CheckArgument(arg, "--progress")) {
} else if (this->CheckArgument(arg, "--progress")) {
this->Impl->TestProgressOutput = true;
}
if (this->CheckArgument(arg, "-V", "--verbose")) {
} else if (this->CheckArgument(arg, "-V", "--verbose")) {
this->Impl->Verbose = true;
}
if (this->CheckArgument(arg, "-VV", "--extra-verbose")) {
} else if (this->CheckArgument(arg, "-VV", "--extra-verbose")) {
this->Impl->ExtraVerbose = true;
this->Impl->Verbose = true;
}
if (this->CheckArgument(arg, "--output-on-failure")) {
} else if (this->CheckArgument(arg, "--output-on-failure")) {
this->Impl->OutputTestOutputOnTestFailure = true;
}
if (this->CheckArgument(arg, "--test-output-size-passed") &&
i < args.size() - 1) {
} else if (this->CheckArgument(arg, "--test-output-size-passed") &&
i < args.size() - 1) {
i++;
long outputSize;
if (cmStrToLong(args[i], &outputSize)) {
@@ -1985,9 +1975,8 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
"Invalid value for '--test-output-size-passed': " << args[i]
<< "\n");
}
}
if (this->CheckArgument(arg, "--test-output-size-failed") &&
i < args.size() - 1) {
} else if (this->CheckArgument(arg, "--test-output-size-failed") &&
i < args.size() - 1) {
i++;
long outputSize;
if (cmStrToLong(args[i], &outputSize)) {
@@ -1997,11 +1986,9 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
"Invalid value for '--test-output-size-failed': " << args[i]
<< "\n");
}
}
if (this->CheckArgument(arg, "-N", "--show-only")) {
} else if (this->CheckArgument(arg, "-N", "--show-only")) {
this->Impl->ShowOnly = true;
}
if (cmHasLiteralPrefix(arg, "--show-only=")) {
} else if (cmHasLiteralPrefix(arg, "--show-only=")) {
this->Impl->ShowOnly = true;
// Check if a specific format is requested. Defaults to human readable
@@ -2019,27 +2006,26 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
}
}
if (this->CheckArgument(arg, "-O", "--output-log") && i < args.size() - 1) {
else if (this->CheckArgument(arg, "-O", "--output-log") &&
i < args.size() - 1) {
i++;
this->SetOutputLogFileName(args[i].c_str());
}
if (this->CheckArgument(arg, "--tomorrow-tag")) {
else if (this->CheckArgument(arg, "--tomorrow-tag")) {
this->Impl->TomorrowTag = true;
}
if (this->CheckArgument(arg, "--force-new-ctest-process")) {
} else if (this->CheckArgument(arg, "--force-new-ctest-process")) {
this->Impl->ForceNewCTestProcess = true;
}
if (this->CheckArgument(arg, "-W", "--max-width") && i < args.size() - 1) {
} else if (this->CheckArgument(arg, "-W", "--max-width") &&
i < args.size() - 1) {
i++;
this->Impl->MaxTestNameWidth = atoi(args[i].c_str());
}
if (this->CheckArgument(arg, "--interactive-debug-mode") &&
i < args.size() - 1) {
} else if (this->CheckArgument(arg, "--interactive-debug-mode") &&
i < args.size() - 1) {
i++;
this->Impl->InteractiveDebugMode = cmIsOn(args[i]);
}
if (this->CheckArgument(arg, "--submit-index") && i < args.size() - 1) {
} else if (this->CheckArgument(arg, "--submit-index") &&
i < args.size() - 1) {
i++;
this->Impl->SubmitIndex = atoi(args[i].c_str());
if (this->Impl->SubmitIndex < 0) {
@@ -2047,15 +2033,16 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
}
}
if (this->CheckArgument(arg, "--overwrite") && i < args.size() - 1) {
else if (this->CheckArgument(arg, "--overwrite") && i < args.size() - 1) {
i++;
this->AddCTestConfigurationOverwrite(args[i]);
}
if (this->CheckArgument(arg, "-A", "--add-notes") && i < args.size() - 1) {
} else if (this->CheckArgument(arg, "-A", "--add-notes") &&
i < args.size() - 1) {
this->Impl->ProduceXML = true;
this->SetTest("Notes");
i++;
this->SetNotesFiles(args[i].c_str());
return true;
}
const std::string noTestsPrefix = "--no-tests=";
@@ -2072,34 +2059,32 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
}
// options that control what tests are run
if (this->CheckArgument(arg, "-I", "--tests-information") &&
i < args.size() - 1) {
else if (this->CheckArgument(arg, "-I", "--tests-information") &&
i < args.size() - 1) {
i++;
this->GetTestHandler()->SetPersistentOption("TestsToRunInformation",
args[i].c_str());
this->GetMemCheckHandler()->SetPersistentOption("TestsToRunInformation",
args[i].c_str());
}
if (this->CheckArgument(arg, "-U", "--union")) {
} else if (this->CheckArgument(arg, "-U", "--union")) {
this->GetTestHandler()->SetPersistentOption("UseUnion", "true");
this->GetMemCheckHandler()->SetPersistentOption("UseUnion", "true");
}
if (this->CheckArgument(arg, "-R", "--tests-regex") && i < args.size() - 1) {
} else if (this->CheckArgument(arg, "-R", "--tests-regex") &&
i < args.size() - 1) {
i++;
this->GetTestHandler()->SetPersistentOption("IncludeRegularExpression",
args[i].c_str());
this->GetMemCheckHandler()->SetPersistentOption("IncludeRegularExpression",
args[i].c_str());
}
if (this->CheckArgument(arg, "-L", "--label-regex") && i < args.size() - 1) {
} else if (this->CheckArgument(arg, "-L", "--label-regex") &&
i < args.size() - 1) {
i++;
this->GetTestHandler()->SetPersistentOption("LabelRegularExpression",
args[i].c_str());
this->GetMemCheckHandler()->SetPersistentOption("LabelRegularExpression",
args[i].c_str());
}
if (this->CheckArgument(arg, "-LE", "--label-exclude") &&
i < args.size() - 1) {
} else if (this->CheckArgument(arg, "-LE", "--label-exclude") &&
i < args.size() - 1) {
i++;
this->GetTestHandler()->SetPersistentOption(
"ExcludeLabelRegularExpression", args[i].c_str());
@@ -2107,8 +2092,8 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
"ExcludeLabelRegularExpression", args[i].c_str());
}
if (this->CheckArgument(arg, "-E", "--exclude-regex") &&
i < args.size() - 1) {
else if (this->CheckArgument(arg, "-E", "--exclude-regex") &&
i < args.size() - 1) {
i++;
this->GetTestHandler()->SetPersistentOption("ExcludeRegularExpression",
args[i].c_str());
@@ -2116,24 +2101,22 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
args[i].c_str());
}
if (this->CheckArgument(arg, "-FA", "--fixture-exclude-any") &&
i < args.size() - 1) {
else if (this->CheckArgument(arg, "-FA", "--fixture-exclude-any") &&
i < args.size() - 1) {
i++;
this->GetTestHandler()->SetPersistentOption(
"ExcludeFixtureRegularExpression", args[i].c_str());
this->GetMemCheckHandler()->SetPersistentOption(
"ExcludeFixtureRegularExpression", args[i].c_str());
}
if (this->CheckArgument(arg, "-FS", "--fixture-exclude-setup") &&
i < args.size() - 1) {
} else if (this->CheckArgument(arg, "-FS", "--fixture-exclude-setup") &&
i < args.size() - 1) {
i++;
this->GetTestHandler()->SetPersistentOption(
"ExcludeFixtureSetupRegularExpression", args[i].c_str());
this->GetMemCheckHandler()->SetPersistentOption(
"ExcludeFixtureSetupRegularExpression", args[i].c_str());
}
if (this->CheckArgument(arg, "-FC", "--fixture-exclude-cleanup") &&
i < args.size() - 1) {
} else if (this->CheckArgument(arg, "-FC", "--fixture-exclude-cleanup") &&
i < args.size() - 1) {
i++;
this->GetTestHandler()->SetPersistentOption(
"ExcludeFixtureCleanupRegularExpression", args[i].c_str());
@@ -2141,8 +2124,8 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
"ExcludeFixtureCleanupRegularExpression", args[i].c_str());
}
if (this->CheckArgument(arg, "--resource-spec-file") &&
i < args.size() - 1) {
else if (this->CheckArgument(arg, "--resource-spec-file") &&
i < args.size() - 1) {
i++;
this->GetTestHandler()->SetPersistentOption("ResourceSpecFile",
args[i].c_str());
@@ -2150,7 +2133,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
args[i].c_str());
}
if (this->CheckArgument(arg, "--rerun-failed")) {
else if (this->CheckArgument(arg, "--rerun-failed")) {
this->GetTestHandler()->SetPersistentOption("RerunFailed", "true");
this->GetMemCheckHandler()->SetPersistentOption("RerunFailed", "true");
}