From b821f9ad62d97b975255380674aaedfce296a8b8 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Thu, 4 Jul 2019 21:04:19 +0300 Subject: Refactor: Optimize some stream output operations - remove redundant `std::flush` right after `std::endl` - join some string literals Signed-off-by: Alex Turbov --- Source/cmCTest.cxx | 24 ++++++++++-------------- Source/cmMessenger.cxx | 3 +-- Source/cmakemain.cxx | 4 +--- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index d1226c3..63b8da4 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1098,9 +1098,10 @@ int cmCTest::RunMakeCommand(const std::string& command, std::string& output, cmProcessOutput processOutput(encoding); std::string strdata; cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, - " Each . represents " << tick_len << " bytes of output" - << std::endl - << " " << std::flush); + " Each . represents " << tick_len + << " bytes of output\n" + " " + << std::flush); while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) { processOutput.DecodeText(data, length, strdata); for (char& cc : strdata) { @@ -1115,8 +1116,7 @@ int cmCTest::RunMakeCommand(const std::string& command, std::string& output, if (tick % tick_line_len == 0 && tick > 0) { cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, " Size: " << int((double(output.size()) / 1024.0) + 1) - << "K" << std::endl - << " " << std::flush); + << "K\n " << std::flush); } } cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, @@ -1324,18 +1324,14 @@ int cmCTest::RunTest(std::vector argv, std::string* output, if (output) { *output += outerr; } - cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, - outerr << std::endl - << std::flush); + cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr << std::endl); } else if (result == cmsysProcess_State_Error) { std::string outerr = "\n*** ERROR executing: "; outerr += cmsysProcess_GetErrorString(cp); if (output) { *output += outerr; } - cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, - outerr << std::endl - << std::flush); + cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr << std::endl); } cmsysProcess_Delete(cp); @@ -3077,11 +3073,11 @@ void cmCTest::Log(int logType, const char* file, int line, const char* msg, } else { *this->Impl->OutputLogFile << cmCTestStringLogType[logType]; } - *this->Impl->OutputLogFile << "] " << std::endl << std::flush; + *this->Impl->OutputLogFile << "] " << std::endl; } *this->Impl->OutputLogFile << msg << std::flush; if (logType != this->Impl->OutputLogFileLastTag) { - *this->Impl->OutputLogFile << std::endl << std::flush; + *this->Impl->OutputLogFile << std::endl; this->Impl->OutputLogFileLastTag = logType; } } @@ -3194,7 +3190,7 @@ void cmCTest::OutputTestErrors(std::vector const& process_output) if (!process_output.empty()) { test_outputs.append(process_output.data(), process_output.size()); } - cmCTestLog(this, HANDLER_OUTPUT, test_outputs << std::endl << std::flush); + cmCTestLog(this, HANDLER_OUTPUT, test_outputs << std::endl); } bool cmCTest::CompressString(std::string& str) diff --git a/Source/cmMessenger.cxx b/Source/cmMessenger.cxx index 1d790e2..0d2b21f 100644 --- a/Source/cmMessenger.cxx +++ b/Source/cmMessenger.cxx @@ -100,8 +100,7 @@ void displayMessage(MessageType t, std::ostringstream& msg) "it."; } else if (t == MessageType::AUTHOR_ERROR) { msg << "This error is for project developers. Use -Wno-error=dev to " - "suppress " - "it."; + "suppress it."; } // Add a terminating blank line. diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index a6348b3..f80829f 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -159,7 +159,7 @@ static std::string cmakemainGetStack(cmake* cm) static void cmakemainMessageCallback(const std::string& m, const char* /*unused*/, cmake* cm) { - std::cerr << m << cmakemainGetStack(cm) << std::endl << std::flush; + std::cerr << m << cmakemainGetStack(cm) << std::endl; } static void cmakemainProgressCallback(const std::string& m, float prog, @@ -178,8 +178,6 @@ static void cmakemainProgressCallback(const std::string& m, float prog, if ((prog < 0) || (!dir.empty())) { std::cout << "-- " << m << dir << cmakemainGetStack(cm) << std::endl; } - - std::cout.flush(); } int main(int ac, char const* const* av) -- cgit v0.12