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);
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<const char*> 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<char> 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)

View File

@ -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.

View File

@ -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)