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

@@ -34,7 +34,7 @@ namespace Catch {
}
virtual void noMatchingTestCases( std::string const& spec ) {
stream << "No test cases matched '" << spec << "'" << std::endl;
stream << "No test cases matched '" << spec << '\'' << std::endl;
}
virtual void assertionStarting( AssertionInfo const& ) {
@@ -61,7 +61,7 @@ namespace Catch {
virtual void testRunEnded( TestRunStats const& _testRunStats ) {
printTotals( _testRunStats.totals );
stream << "\n" << std::endl;
stream << '\n' << std::endl;
StreamingReporterBase::testRunEnded( _testRunStats );
}
@@ -161,26 +161,26 @@ namespace Catch {
void printSourceInfo() const {
Colour colourGuard( Colour::FileName );
stream << result.getSourceInfo() << ":";
stream << result.getSourceInfo() << ':';
}
void printResultType( Colour::Code colour, std::string passOrFail ) const {
if( !passOrFail.empty() ) {
{
Colour colourGuard( colour );
stream << " " << passOrFail;
stream << ' ' << passOrFail;
}
stream << ":";
stream << ':';
}
}
void printIssue( std::string issue ) const {
stream << " " << issue;
stream << ' ' << issue;
}
void printExpressionWas() {
if( result.hasExpression() ) {
stream << ";";
stream << ';';
{
Colour colour( dimColour() );
stream << " expression was:";
@@ -191,7 +191,7 @@ namespace Catch {
void printOriginalExpression() const {
if( result.hasExpression() ) {
stream << " " << result.getExpression();
stream << ' ' << result.getExpression();
}
}
@@ -207,7 +207,7 @@ namespace Catch {
void printMessage() {
if ( itMessage != messages.end() ) {
stream << " '" << itMessage->message << "'";
stream << " '" << itMessage->message << '\'';
++itMessage;
}
}
@@ -222,13 +222,13 @@ namespace Catch {
{
Colour colourGuard( colour );
stream << " with " << pluralise( N, "message" ) << ":";
stream << " with " << pluralise( N, "message" ) << ':';
}
for(; itMessage != itEnd; ) {
// If this assertion is a warning ignore any INFO messages
if( printInfoMessages || itMessage->type != ResultWas::Info ) {
stream << " '" << itMessage->message << "'";
stream << " '" << itMessage->message << '\'';
if ( ++itMessage != itEnd ) {
Colour colourGuard( dimColour() );
stream << " and";
@@ -254,7 +254,7 @@ namespace Catch {
// - green: Passed [both/all] N tests cases with M assertions.
std::string bothOrAll( std::size_t count ) const {
return count == 1 ? "" : count == 2 ? "both " : "all " ;
return count == 1 ? std::string() : count == 2 ? "both " : "all " ;
}
void printTotals( const Totals& totals ) const {
@@ -265,12 +265,12 @@ namespace Catch {
Colour colour( Colour::ResultError );
const std::string qualify_assertions_failed =
totals.assertions.failed == totals.assertions.total() ?
bothOrAll( totals.assertions.failed ) : "";
bothOrAll( totals.assertions.failed ) : std::string();
stream <<
"Failed " << bothOrAll( totals.testCases.failed )
<< pluralise( totals.testCases.failed, "test case" ) << ", "
"failed " << qualify_assertions_failed <<
pluralise( totals.assertions.failed, "assertion" ) << ".";
pluralise( totals.assertions.failed, "assertion" ) << '.';
}
else if( totals.assertions.total() == 0 ) {
stream <<
@@ -282,14 +282,14 @@ namespace Catch {
Colour colour( Colour::ResultError );
stream <<
"Failed " << pluralise( totals.testCases.failed, "test case" ) << ", "
"failed " << pluralise( totals.assertions.failed, "assertion" ) << ".";
"failed " << pluralise( totals.assertions.failed, "assertion" ) << '.';
}
else {
Colour colour( Colour::ResultSuccess );
stream <<
"Passed " << bothOrAll( totals.testCases.passed )
<< pluralise( totals.testCases.passed, "test case" ) <<
" with " << pluralise( totals.assertions.passed, "assertion" ) << ".";
" with " << pluralise( totals.assertions.passed, "assertion" ) << '.';
}
}
};

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:

View File

@@ -146,7 +146,7 @@ namespace Catch {
SectionNode const& sectionNode ) {
std::string name = trim( sectionNode.stats.sectionInfo.name );
if( !rootName.empty() )
name = rootName + "/" + name;
name = rootName + '/' + name;
if( !sectionNode.assertions.empty() ||
!sectionNode.stdOut.empty() ||
@@ -224,14 +224,14 @@ namespace Catch {
std::ostringstream oss;
if( !result.getMessage().empty() )
oss << result.getMessage() << "\n";
oss << result.getMessage() << '\n';
for( std::vector<MessageInfo>::const_iterator
it = stats.infoMessages.begin(),
itEnd = stats.infoMessages.end();
it != itEnd;
++it )
if( it->type == ResultWas::Info )
oss << it->message << "\n";
oss << it->message << '\n';
oss << "at " << result.getSourceInfo();
xml.writeText( oss.str(), false );