Merge topic 'prefer-front-back-over-begin-rbegin'

f3534386b5 Prefer front/back/data over dereferencing begin/rbegin iter

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Daniel Pfeifer <daniel@pfeifer-mail.de>
Merge-request: !2914
This commit is contained in:
Brad King
2019-02-07 18:30:22 +00:00
committed by Kitware Robot
22 changed files with 64 additions and 65 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ int main(int argc, char* argv[])
args.push_back(nullptr);
cmsysProcess* cp = cmsysProcess_New();
cmsysProcess_SetCommand(cp, &*args.begin());
cmsysProcess_SetCommand(cp, args.data());
cmsysProcess_SetWorkingDirectory(cp, scriptDirectory.c_str());
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
cmsysProcess_SetTimeout(cp, 0);
+2 -2
View File
@@ -800,7 +800,7 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal,
// Now create process object
cmsysProcess* cp = cmsysProcess_New();
cmsysProcess_SetCommand(cp, &*argv.begin());
cmsysProcess_SetCommand(cp, argv.data());
cmsysProcess_SetWorkingDirectory(cp, dir);
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
cmsysProcess_SetTimeout(cp, timeout);
@@ -978,7 +978,7 @@ void cmCTestBuildHandler::ProcessBuffer(const char* data, size_t length,
this->CurrentProcessingLine.insert(this->CurrentProcessingLine.end(),
queue->begin(), it);
this->CurrentProcessingLine.push_back(0);
const char* line = &*this->CurrentProcessingLine.begin();
const char* line = this->CurrentProcessingLine.data();
// Process the line
int lineType = this->ProcessSingleLine(line);
+1 -1
View File
@@ -72,7 +72,7 @@ public:
args.push_back(cl.c_str());
}
args.push_back(nullptr); // null terminate
cmsysProcess_SetCommand(this->Process, &*args.begin());
cmsysProcess_SetCommand(this->Process, args.data());
if (!this->WorkingDirectory.empty()) {
cmsysProcess_SetWorkingDirectory(this->Process,
this->WorkingDirectory.c_str());
+1 -1
View File
@@ -199,7 +199,7 @@ int cmCTestScriptHandler::ExecuteScript(const std::string& total_script_arg)
// Now create process object
cmsysProcess* cp = cmsysProcess_New();
cmsysProcess_SetCommand(cp, &*argv.begin());
cmsysProcess_SetCommand(cp, argv.data());
// cmsysProcess_SetWorkingDirectory(cp, dir);
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
// cmsysProcess_SetTimeout(cp, timeout);
+10 -11
View File
@@ -343,7 +343,7 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(
if (!chunk.empty()) {
cmCTestOptionalLog(this->CTest, DEBUG,
"CURL output: ["
<< cmCTestLogWrite(&*chunk.begin(), chunk.size())
<< cmCTestLogWrite(chunk.data(), chunk.size())
<< "]" << std::endl,
this->Quiet);
this->ParseResponse(chunk);
@@ -352,7 +352,7 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(
cmCTestOptionalLog(
this->CTest, DEBUG,
"CURL debug output: ["
<< cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
<< cmCTestLogWrite(chunkDebug.data(), chunkDebug.size()) << "]"
<< std::endl,
this->Quiet);
}
@@ -404,12 +404,11 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(
res = ::curl_easy_perform(curl);
if (!chunk.empty()) {
cmCTestOptionalLog(
this->CTest, DEBUG,
"CURL output: ["
<< cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
<< std::endl,
this->Quiet);
cmCTestOptionalLog(this->CTest, DEBUG,
"CURL output: ["
<< cmCTestLogWrite(chunk.data(), chunk.size())
<< "]" << std::endl,
this->Quiet);
this->ParseResponse(chunk);
}
@@ -433,11 +432,11 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(
// avoid deref of begin for zero size array
if (!chunk.empty()) {
*this->LogFile << " Curl output was: "
<< cmCTestLogWrite(&*chunk.begin(), chunk.size())
<< cmCTestLogWrite(chunk.data(), chunk.size())
<< std::endl;
cmCTestLog(this->CTest, ERROR_MESSAGE,
"CURL output: ["
<< cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
<< cmCTestLogWrite(chunk.data(), chunk.size()) << "]"
<< std::endl);
}
::curl_easy_cleanup(curl);
@@ -486,7 +485,7 @@ void cmCTestSubmitHandler::ParseResponse(
if (this->HasWarnings || this->HasErrors) {
cmCTestLog(this->CTest, HANDLER_OUTPUT,
" Server Response:\n"
<< cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "\n");
<< cmCTestLogWrite(chunk.data(), chunk.size()) << "\n");
}
}
+2 -2
View File
@@ -199,7 +199,7 @@ bool cmProcess::Buffer::GetLine(std::string& line)
for (size_type sz = this->size(); this->Last != sz; ++this->Last) {
if ((*this)[this->Last] == '\n' || (*this)[this->Last] == '\0') {
// Extract the range first..last as a line.
const char* text = &*this->begin() + this->First;
const char* text = this->data() + this->First;
size_type length = this->Last - this->First;
while (length && text[length - 1] == '\r') {
length--;
@@ -229,7 +229,7 @@ bool cmProcess::Buffer::GetLast(std::string& line)
{
// Return the partial last line, if any.
if (!this->empty()) {
line.assign(&*this->begin(), this->size());
line.assign(this->data(), this->size());
this->First = this->Last = 0;
this->clear();
return true;
+7 -7
View File
@@ -1039,7 +1039,7 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output,
// Now create process object
cmsysProcess* cp = cmsysProcess_New();
cmsysProcess_SetCommand(cp, &*argv.begin());
cmsysProcess_SetCommand(cp, argv.data());
cmsysProcess_SetWorkingDirectory(cp, dir);
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
cmsysProcess_SetTimeout(cp, timeout.count());
@@ -1222,7 +1222,7 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output,
}
cmsysProcess* cp = cmsysProcess_New();
cmsysProcess_SetCommand(cp, &*argv.begin());
cmsysProcess_SetCommand(cp, argv.data());
cmCTestLog(this, DEBUG, "Command is: " << argv[0] << std::endl);
if (cmSystemTools::GetRunCommandHideConsole()) {
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
@@ -1258,7 +1258,7 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output,
cmsysProcess_WaitForExit(cp, nullptr);
processOutput.DecodeText(tempOutput, tempOutput);
if (output && tempOutput.begin() != tempOutput.end()) {
output->append(&*tempOutput.begin(), tempOutput.size());
output->append(tempOutput.data(), tempOutput.size());
}
cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
"-- Process completed" << std::endl);
@@ -2776,7 +2776,7 @@ bool cmCTest::RunCommand(std::vector<std::string> const& args,
stdErr->clear();
cmsysProcess* cp = cmsysProcess_New();
cmsysProcess_SetCommand(cp, &*argv.begin());
cmsysProcess_SetCommand(cp, argv.data());
cmsysProcess_SetWorkingDirectory(cp, dir);
if (cmSystemTools::GetRunCommandHideConsole()) {
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
@@ -2820,11 +2820,11 @@ bool cmCTest::RunCommand(std::vector<std::string> const& args,
cmsysProcess_WaitForExit(cp, nullptr);
if (!tempOutput.empty()) {
processOutput.DecodeText(tempOutput, tempOutput);
stdOut->append(&*tempOutput.begin(), tempOutput.size());
stdOut->append(tempOutput.data(), tempOutput.size());
}
if (!tempError.empty()) {
processOutput.DecodeText(tempError, tempError);
stdErr->append(&*tempError.begin(), tempError.size());
stdErr->append(tempError.data(), tempError.size());
}
bool result = true;
@@ -3048,7 +3048,7 @@ void cmCTest::OutputTestErrors(std::vector<char> const& process_output)
{
std::string test_outputs("\n*** Test Failed:\n");
if (!process_output.empty()) {
test_outputs.append(&*process_output.begin(), process_output.size());
test_outputs.append(process_output.data(), process_output.size());
}
cmCTestLog(this, HANDLER_OUTPUT, test_outputs << std::endl << std::flush);
}
+2 -2
View File
@@ -130,8 +130,8 @@ bool cmConditionEvaluator::IsTrue(
return false;
}
return this->GetBooleanValueWithAutoDereference(*(newArgs.begin()),
errorString, status, true);
return this->GetBooleanValueWithAutoDereference(newArgs.front(), errorString,
status, true);
}
//=========================================================================
+3 -3
View File
@@ -193,7 +193,7 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
// Set the command sequence.
for (auto const& cmd : cmds) {
cmsysProcess_AddCommand(cp, &*cmd.begin());
cmsysProcess_AddCommand(cp, cmd.data());
}
// Set the process working directory.
@@ -286,10 +286,10 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
// Store the output obtained.
if (!output_variable.empty() && !tempOutput.empty()) {
this->Makefile->AddDefinition(output_variable, &*tempOutput.begin());
this->Makefile->AddDefinition(output_variable, tempOutput.data());
}
if (!merge_output && !error_variable.empty() && !tempError.empty()) {
this->Makefile->AddDefinition(error_variable, &*tempError.begin());
this->Makefile->AddDefinition(error_variable, tempError.data());
}
// Store the result of running the process.
+3 -3
View File
@@ -3067,7 +3067,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
if (!logVar.empty()) {
chunkDebug.push_back(0);
this->Makefile->AddDefinition(logVar, &*chunkDebug.begin());
this->Makefile->AddDefinition(logVar, chunkDebug.data());
}
return true;
@@ -3326,14 +3326,14 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
if (!chunkResponse.empty()) {
chunkResponse.push_back(0);
log += "Response:\n";
log += &*chunkResponse.begin();
log += chunkResponse.data();
log += "\n";
}
if (!chunkDebug.empty()) {
chunkDebug.push_back(0);
log += "Debug:\n";
log += &*chunkDebug.begin();
log += chunkDebug.data();
log += "\n";
}
+1 -1
View File
@@ -74,7 +74,7 @@ std::string cmFilePathChecksum::get(std::string const& filePath) const
cmCryptoHash(cmCryptoHash::AlgoSHA256).ByteHashString(relSeed + relPath);
// Convert binary checksum to string
return cmBase32Encoder().encodeString(&hashBytes.front(), hashBytes.size(),
return cmBase32Encoder().encodeString(hashBytes.data(), hashBytes.size(),
false);
}
+1 -1
View File
@@ -310,7 +310,7 @@ void cmFindCommon::AddPathSuffix(std::string const& arg)
void AddTrailingSlash(std::string& s)
{
if (!s.empty() && *s.rbegin() != '/') {
if (!s.empty() && s.back() != '/') {
s += '/';
}
}
+1 -1
View File
@@ -466,7 +466,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args,
// Allocate a PACKAGE_ROOT_PATH for the current find_package call.
this->Makefile->FindPackageRootPathStack.emplace_back();
std::vector<std::string>& rootPaths =
*this->Makefile->FindPackageRootPathStack.rbegin();
this->Makefile->FindPackageRootPathStack.back();
// Add root paths from <PackageName>_ROOT CMake and environment variables,
// subject to CMP0074.
+16 -16
View File
@@ -135,13 +135,13 @@ static const struct NotNode : public cmGeneratorExpressionNode
const GeneratorExpressionContent* content,
cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
if (*parameters.begin() != "0" && *parameters.begin() != "1") {
if (parameters.front() != "0" && parameters.front() != "1") {
reportError(
context, content->GetOriginalExpression(),
"$<NOT> parameter must resolve to exactly one '0' or '1' value.");
return std::string();
}
return *parameters.begin() == "0" ? "1" : "0";
return parameters.front() == "0" ? "1" : "0";
}
} notNode;
@@ -157,7 +157,7 @@ static const struct BoolNode : public cmGeneratorExpressionNode
const GeneratorExpressionContent* /*content*/,
cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
return !cmSystemTools::IsOff(*parameters.begin()) ? "1" : "0";
return !cmSystemTools::IsOff(parameters.front()) ? "1" : "0";
}
} boolNode;
@@ -194,7 +194,7 @@ static const struct StrEqualNode : public cmGeneratorExpressionNode
const GeneratorExpressionContent* /*content*/,
cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
return *parameters.begin() == parameters[1] ? "1" : "0";
return parameters.front() == parameters[1] ? "1" : "0";
}
} strEqualNode;
@@ -613,7 +613,7 @@ struct CompilerIdNode : public cmGeneratorExpressionNode
return compilerId;
}
static cmsys::RegularExpression compilerIdValidator("^[A-Za-z0-9_]*$");
if (!compilerIdValidator.find(*parameters.begin())) {
if (!compilerIdValidator.find(parameters.front())) {
reportError(context, content->GetOriginalExpression(),
"Expression syntax not recognized.");
return std::string();
@@ -622,11 +622,11 @@ struct CompilerIdNode : public cmGeneratorExpressionNode
return parameters.front().empty() ? "1" : "0";
}
if (strcmp(parameters.begin()->c_str(), compilerId.c_str()) == 0) {
if (strcmp(parameters.front().c_str(), compilerId.c_str()) == 0) {
return "1";
}
if (cmsysString_strcasecmp(parameters.begin()->c_str(),
if (cmsysString_strcasecmp(parameters.front().c_str(),
compilerId.c_str()) == 0) {
switch (context->LG->GetPolicyStatus(cmPolicies::CMP0044)) {
case cmPolicies::WARN: {
@@ -734,7 +734,7 @@ struct CompilerVersionNode : public cmGeneratorExpressionNode
}
static cmsys::RegularExpression compilerIdValidator("^[0-9\\.]*$");
if (!compilerIdValidator.find(*parameters.begin())) {
if (!compilerIdValidator.find(parameters.front())) {
reportError(context, content->GetOriginalExpression(),
"Expression syntax not recognized.");
return std::string();
@@ -744,7 +744,7 @@ struct CompilerVersionNode : public cmGeneratorExpressionNode
}
return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL,
parameters.begin()->c_str(),
parameters.front().c_str(),
compilerVersion.c_str())
? "1"
: "0";
@@ -839,7 +839,7 @@ struct PlatformIdNode : public cmGeneratorExpressionNode
return parameters.front().empty() ? "1" : "0";
}
if (*parameters.begin() == platformId) {
if (parameters.front() == platformId) {
return "1";
}
return "0";
@@ -1001,7 +1001,7 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
return configurationNode.Evaluate(parameters, context, content, nullptr);
}
static cmsys::RegularExpression configValidator("^[A-Za-z0-9_]*$");
if (!configValidator.find(*parameters.begin())) {
if (!configValidator.find(parameters.front())) {
reportError(context, content->GetOriginalExpression(),
"Expression syntax not recognized.");
return std::string();
@@ -1011,7 +1011,7 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
return parameters.front().empty() ? "1" : "0";
}
if (cmsysString_strcasecmp(parameters.begin()->c_str(),
if (cmsysString_strcasecmp(parameters.front().c_str(),
context->Config.c_str()) == 0) {
return "1";
}
@@ -1166,7 +1166,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
static cmsys::RegularExpression propertyNameValidator("^[A-Za-z0-9_]+$");
cmGeneratorTarget const* target = context->HeadTarget;
std::string propertyName = *parameters.begin();
std::string propertyName = parameters.front();
if (parameters.size() == 1) {
context->HadHeadSensitiveCondition = true;
@@ -1182,14 +1182,14 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
}
if (parameters.size() == 2) {
if (parameters.begin()->empty() && parameters[1].empty()) {
if (parameters.front().empty() && parameters[1].empty()) {
reportError(
context, content->GetOriginalExpression(),
"$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
"target name and property name.");
return std::string();
}
if (parameters.begin()->empty()) {
if (parameters.front().empty()) {
reportError(
context, content->GetOriginalExpression(),
"$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
@@ -1964,7 +1964,7 @@ struct TargetFilesystemArtifact : public cmGeneratorExpressionNode
cmGeneratorExpressionDAGChecker* dagChecker) const override
{
// Lookup the referenced target.
std::string name = *parameters.begin();
std::string name = parameters.front();
if (!cmGeneratorExpression::IsValidTargetName(name)) {
::reportError(context, content->GetOriginalExpression(),
+3 -3
View File
@@ -47,11 +47,11 @@ static void extendResult(
if (!result.empty() &&
(*(result.end() - 1))->GetType() ==
cmGeneratorExpressionEvaluator::Text &&
(*contents.begin())->GetType() == cmGeneratorExpressionEvaluator::Text) {
contents.front()->GetType() == cmGeneratorExpressionEvaluator::Text) {
TextContent* textContent = static_cast<TextContent*>(*(result.end() - 1));
textContent->Extend(
static_cast<TextContent*>(*contents.begin())->GetLength());
delete *contents.begin();
static_cast<TextContent*>(contents.front())->GetLength());
delete contents.front();
result.insert(result.end(), contents.begin() + 1, contents.end());
} else {
result.insert(result.end(), contents.begin(), contents.end());
+1 -1
View File
@@ -2389,7 +2389,7 @@ void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc)
std::set<cmGeneratorTarget*> targets;
for (cmCustomCommandLine const& cCmdLine : cc.GetCommandLines()) {
std::string const& command = *cCmdLine.begin();
std::string const& command = cCmdLine.front();
// Check for a target with this name.
if (cmGeneratorTarget* t =
this->LocalGenerator->FindGeneratorTargetToUse(command)) {
+1 -1
View File
@@ -2193,7 +2193,7 @@ cmSourceGroup* cmMakefile::FindSourceGroup(
}
// Shouldn't get here, but just in case, return the default group.
return &groups.front();
return groups.data();
}
#endif
+3 -3
View File
@@ -447,7 +447,7 @@ void cmQtAutoGenerator::ReadOnlyProcessT::PipeT::UVAlloc(uv_handle_t* handle,
{
auto& pipe = *reinterpret_cast<PipeT*>(handle->data);
pipe.Buffer_.resize(suggestedSize);
buf->base = &pipe.Buffer_.front();
buf->base = pipe.Buffer_.data();
buf->len = pipe.Buffer_.size();
}
@@ -555,11 +555,11 @@ bool cmQtAutoGenerator::ReadOnlyProcessT::start(
std::fill_n(reinterpret_cast<char*>(&UVOptions_), sizeof(UVOptions_), 0);
UVOptions_.exit_cb = &ReadOnlyProcessT::UVExit;
UVOptions_.file = CommandPtr_[0];
UVOptions_.args = const_cast<char**>(&CommandPtr_.front());
UVOptions_.args = const_cast<char**>(CommandPtr_.data());
UVOptions_.cwd = Setup_.WorkingDirectory.c_str();
UVOptions_.flags = UV_PROCESS_WINDOWS_HIDE;
UVOptions_.stdio_count = static_cast<int>(UVOptionsStdIO_.size());
UVOptions_.stdio = &UVOptionsStdIO_.front();
UVOptions_.stdio = UVOptionsStdIO_.data();
// -- Spawn process
if (UVProcess_.spawn(*uv_loop, UVOptions_, this) != 0) {
+2 -2
View File
@@ -144,7 +144,7 @@ void cmSearchPath::AddSuffixes(const std::vector<std::string>& suffixes)
// this will get incorrectly considered a network
// path on windows and cause huge delays.
std::string p = inPath;
if (!p.empty() && *p.rbegin() != '/') {
if (!p.empty() && p.back() != '/') {
p += "/";
}
@@ -176,7 +176,7 @@ void cmSearchPath::AddPrefixPaths(const std::vector<std::string>& paths,
for (std::string const& path : paths) {
std::string dir = path;
if (!subdir.empty() && !dir.empty() && *dir.rbegin() != '/') {
if (!subdir.empty() && !dir.empty() && dir.back() != '/') {
dir += "/";
}
if (subdir == "include" || subdir == "lib") {
+1 -1
View File
@@ -771,7 +771,7 @@ bool cmStringCommand::HandleRandomCommand(std::vector<std::string> const& args)
}
result.push_back(0);
this->Makefile->AddDefinition(variableName, &*result.begin());
this->Makefile->AddDefinition(variableName, result.data());
return true;
}
+1 -1
View File
@@ -740,7 +740,7 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command,
argv.push_back(nullptr);
cmsysProcess* cp = cmsysProcess_New();
cmsysProcess_SetCommand(cp, &*argv.begin());
cmsysProcess_SetCommand(cp, argv.data());
cmsysProcess_SetWorkingDirectory(cp, dir);
if (cmSystemTools::GetRunCommandHideConsole()) {
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
+1 -1
View File
@@ -22,7 +22,7 @@ int RunXCode(std::vector<const char*>& argv, bool& hitbug)
{
hitbug = false;
cmsysProcess* cp = cmsysProcess_New();
cmsysProcess_SetCommand(cp, &*argv.begin());
cmsysProcess_SetCommand(cp, argv.data());
cmsysProcess_SetTimeout(cp, 0);
cmsysProcess_Execute(cp);
std::vector<char> out;