Refactor: Optimize some stream output operations

- remove redundant `std::flush` right after `std::endl`
- join some string literals

Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
This commit is contained in:
Alex Turbov 2019-07-04 21:04:19 +03:00
parent f374ffb14b
commit b821f9ad62
3 changed files with 12 additions and 19 deletions

View File

@ -1098,9 +1098,10 @@ int cmCTest::RunMakeCommand(const std::string& command, std::string& output,
cmProcessOutput processOutput(encoding); cmProcessOutput processOutput(encoding);
std::string strdata; std::string strdata;
cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, cmCTestLog(this, HANDLER_PROGRESS_OUTPUT,
" Each . represents " << tick_len << " bytes of output" " Each . represents " << tick_len
<< std::endl << " bytes of output\n"
<< " " << std::flush); " "
<< std::flush);
while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) { while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) {
processOutput.DecodeText(data, length, strdata); processOutput.DecodeText(data, length, strdata);
for (char& cc : 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) { if (tick % tick_line_len == 0 && tick > 0) {
cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, cmCTestLog(this, HANDLER_PROGRESS_OUTPUT,
" Size: " << int((double(output.size()) / 1024.0) + 1) " Size: " << int((double(output.size()) / 1024.0) + 1)
<< "K" << std::endl << "K\n " << std::flush);
<< " " << std::flush);
} }
} }
cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
@ -1324,18 +1324,14 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output,
if (output) { if (output) {
*output += outerr; *output += outerr;
} }
cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr << std::endl);
outerr << std::endl
<< std::flush);
} else if (result == cmsysProcess_State_Error) { } else if (result == cmsysProcess_State_Error) {
std::string outerr = "\n*** ERROR executing: "; std::string outerr = "\n*** ERROR executing: ";
outerr += cmsysProcess_GetErrorString(cp); outerr += cmsysProcess_GetErrorString(cp);
if (output) { if (output) {
*output += outerr; *output += outerr;
} }
cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr << std::endl);
outerr << std::endl
<< std::flush);
} }
cmsysProcess_Delete(cp); cmsysProcess_Delete(cp);
@ -3077,11 +3073,11 @@ void cmCTest::Log(int logType, const char* file, int line, const char* msg,
} else { } else {
*this->Impl->OutputLogFile << cmCTestStringLogType[logType]; *this->Impl->OutputLogFile << cmCTestStringLogType[logType];
} }
*this->Impl->OutputLogFile << "] " << std::endl << std::flush; *this->Impl->OutputLogFile << "] " << std::endl;
} }
*this->Impl->OutputLogFile << msg << std::flush; *this->Impl->OutputLogFile << msg << std::flush;
if (logType != this->Impl->OutputLogFileLastTag) { if (logType != this->Impl->OutputLogFileLastTag) {
*this->Impl->OutputLogFile << std::endl << std::flush; *this->Impl->OutputLogFile << std::endl;
this->Impl->OutputLogFileLastTag = logType; this->Impl->OutputLogFileLastTag = logType;
} }
} }
@ -3194,7 +3190,7 @@ void cmCTest::OutputTestErrors(std::vector<char> const& process_output)
if (!process_output.empty()) { if (!process_output.empty()) {
test_outputs.append(process_output.data(), process_output.size()); 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) bool cmCTest::CompressString(std::string& str)

View File

@ -100,8 +100,7 @@ void displayMessage(MessageType t, std::ostringstream& msg)
"it."; "it.";
} else if (t == MessageType::AUTHOR_ERROR) { } else if (t == MessageType::AUTHOR_ERROR) {
msg << "This error is for project developers. Use -Wno-error=dev to " msg << "This error is for project developers. Use -Wno-error=dev to "
"suppress " "suppress it.";
"it.";
} }
// Add a terminating blank line. // Add a terminating blank line.

View File

@ -159,7 +159,7 @@ static std::string cmakemainGetStack(cmake* cm)
static void cmakemainMessageCallback(const std::string& m, static void cmakemainMessageCallback(const std::string& m,
const char* /*unused*/, cmake* cm) 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, 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())) { if ((prog < 0) || (!dir.empty())) {
std::cout << "-- " << m << dir << cmakemainGetStack(cm) << std::endl; std::cout << "-- " << m << dir << cmakemainGetStack(cm) << std::endl;
} }
std::cout.flush();
} }
int main(int ac, char const* const* av) int main(int ac, char const* const* av)