Use char literal instead of string literal with 1 char

In reality, this is a relatively small performance improvement,
especially with the previous improvements removing lots of superfluous
string handling, but still was measurable.
This commit is contained in:
Martin Hořeňovský
2017-01-29 23:07:15 +01:00
parent efab3ca8b2
commit bcaa2f9646
13 changed files with 72 additions and 72 deletions

View File

@@ -27,7 +27,7 @@ namespace Catch {
}
virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE {
stream << "No test cases matched '" << spec << "'" << std::endl;
stream << "No test cases matched '" << spec << '\'' << std::endl;
}
virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {
@@ -69,12 +69,12 @@ namespace Catch {
}
if( m_headerPrinted ) {
if( m_config->showDurations() == ShowDurations::Always )
stream << "Completed in " << _sectionStats.durationInSeconds << "s" << std::endl;
stream << "Completed in " << _sectionStats.durationInSeconds << 's' << std::endl;
m_headerPrinted = false;
}
else {
if( m_config->showDurations() == ShowDurations::Always )
stream << _sectionStats.sectionInfo.name << " completed in " << _sectionStats.durationInSeconds << "s" << std::endl;
stream << _sectionStats.sectionInfo.name << " completed in " << _sectionStats.durationInSeconds << 's' << std::endl;
}
StreamingReporterBase::sectionEnded( _sectionStats );
}
@@ -88,7 +88,7 @@ namespace Catch {
printSummaryDivider();
stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n";
printTotals( _testGroupStats.totals );
stream << "\n" << std::endl;
stream << '\n' << std::endl;
}
StreamingReporterBase::testGroupEnded( _testGroupStats );
}
@@ -180,13 +180,13 @@ namespace Catch {
printSourceInfo();
if( stats.totals.assertions.total() > 0 ) {
if( result.isOk() )
stream << "\n";
stream << '\n';
printResultType();
printOriginalExpression();
printReconstructedExpression();
}
else {
stream << "\n";
stream << '\n';
}
printMessage();
}
@@ -203,25 +203,25 @@ namespace Catch {
Colour colourGuard( Colour::OriginalExpression );
stream << " ";
stream << result.getExpressionInMacro();
stream << "\n";
stream << '\n';
}
}
void printReconstructedExpression() const {
if( result.hasExpandedExpression() ) {
stream << "with expansion:\n";
Colour colourGuard( Colour::ReconstructedExpression );
stream << Text( result.getExpandedExpression(), TextAttributes().setIndent(2) ) << "\n";
stream << Text( result.getExpandedExpression(), TextAttributes().setIndent(2) ) << '\n';
}
}
void printMessage() const {
if( !messageLabel.empty() )
stream << messageLabel << ":" << "\n";
stream << messageLabel << ':' << '\n';
for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end();
it != itEnd;
++it ) {
// If this assertion is a warning ignore any INFO messages
if( printInfoMessages || it->type != ResultWas::Info )
stream << Text( it->message, TextAttributes().setIndent(2) ) << "\n";
stream << Text( it->message, TextAttributes().setIndent(2) ) << '\n';
}
}
void printSourceInfo() const {
@@ -253,7 +253,7 @@ namespace Catch {
}
}
void lazyPrintRunInfo() {
stream << "\n" << getLineOfChars<'~'>() << "\n";
stream << '\n' << getLineOfChars<'~'>() << '\n';
Colour colour( Colour::SecondaryText );
stream << currentTestRunInfo->name
<< " is a Catch v" << libraryVersion << " host application.\n"
@@ -287,19 +287,19 @@ namespace Catch {
SourceLineInfo lineInfo = m_sectionStack.front().lineInfo;
if( !lineInfo.empty() ){
stream << getLineOfChars<'-'>() << "\n";
stream << getLineOfChars<'-'>() << '\n';
Colour colourGuard( Colour::FileName );
stream << lineInfo << "\n";
stream << lineInfo << '\n';
}
stream << getLineOfChars<'.'>() << "\n" << std::endl;
stream << getLineOfChars<'.'>() << '\n' << std::endl;
}
void printClosedHeader( std::string const& _name ) {
printOpenHeader( _name );
stream << getLineOfChars<'.'>() << "\n";
stream << getLineOfChars<'.'>() << '\n';
}
void printOpenHeader( std::string const& _name ) {
stream << getLineOfChars<'-'>() << "\n";
stream << getLineOfChars<'-'>() << '\n';
{
Colour colourGuard( Colour::Headers );
printHeaderString( _name );
@@ -316,7 +316,7 @@ namespace Catch {
i = 0;
stream << Text( _string, TextAttributes()
.setIndent( indent+i)
.setInitialIndent( indent ) ) << "\n";
.setInitialIndent( indent ) ) << '\n';
}
struct SummaryColumn {
@@ -331,9 +331,9 @@ namespace Catch {
std::string row = oss.str();
for( std::vector<std::string>::iterator it = rows.begin(); it != rows.end(); ++it ) {
while( it->size() < row.size() )
*it = " " + *it;
*it = ' ' + *it;
while( it->size() > row.size() )
row = " " + row;
row = ' ' + row;
}
rows.push_back( row );
return *this;
@@ -353,8 +353,8 @@ namespace Catch {
stream << Colour( Colour::ResultSuccess ) << "All tests passed";
stream << " ("
<< pluralise( totals.assertions.passed, "assertion" ) << " in "
<< pluralise( totals.testCases.passed, "test case" ) << ")"
<< "\n";
<< pluralise( totals.testCases.passed, "test case" ) << ')'
<< '\n';
}
else {
@@ -389,10 +389,10 @@ namespace Catch {
else if( value != "0" ) {
stream << Colour( Colour::LightGrey ) << " | ";
stream << Colour( it->colour )
<< value << " " << it->label;
<< value << ' ' << it->label;
}
}
stream << "\n";
stream << '\n';
}
static std::size_t makeRatio( std::size_t number, std::size_t total ) {
@@ -428,10 +428,10 @@ namespace Catch {
else {
stream << Colour( Colour::Warning ) << std::string( CATCH_CONFIG_CONSOLE_WIDTH-1, '=' );
}
stream << "\n";
stream << '\n';
}
void printSummaryDivider() {
stream << getLineOfChars<'-'>() << "\n";
stream << getLineOfChars<'-'>() << '\n';
}
private: