From 27c6f017a1ef7c62f7f0332d624add7e8189f81c Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 14 Jan 2015 21:27:25 +0100 Subject: [PATCH] Use cmJoin to accumulate string ranges. Avoid using the std::accumulate algorithm which is designed for numeric types, not complex types. It introduces unneccessary copies. Initialize variables where they are populated. --- Source/cmFileCommand.cxx | 6 +----- Source/cmMessageCommand.cxx | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 8b893bc7a..212603ceb 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -217,7 +217,6 @@ bool cmFileCommand bool cmFileCommand::HandleWriteCommand(std::vector const& args, bool append) { - std::string message; std::vector::const_iterator i = args.begin(); i++; // Get rid of subcommand @@ -231,10 +230,6 @@ bool cmFileCommand::HandleWriteCommand(std::vector const& args, i++; - for(;i != args.end(); ++i) - { - message += *i; - } if ( !this->Makefile->CanIWriteThisFile(fileName.c_str()) ) { std::string e @@ -272,6 +267,7 @@ bool cmFileCommand::HandleWriteCommand(std::vector const& args, this->SetError(error); return false; } + std::string message = cmJoin(cmRange(i, args.end()), std::string()); file << message; file.close(); if(mode) diff --git a/Source/cmMessageCommand.cxx b/Source/cmMessageCommand.cxx index 88d6a771b..0449c501d 100644 --- a/Source/cmMessageCommand.cxx +++ b/Source/cmMessageCommand.cxx @@ -20,7 +20,6 @@ bool cmMessageCommand this->SetError("called with incorrect number of arguments"); return false; } - std::string message; std::vector::const_iterator i = args.begin(); cmake::MessageType type = cmake::MESSAGE; @@ -70,10 +69,7 @@ bool cmMessageCommand ++i; } - for(;i != args.end(); ++i) - { - message += *i; - } + std::string message = cmJoin(cmRange(i, args.end()), std::string()); if (type != cmake::MESSAGE) {