From ece64c3b3aee6256be32f1f860b5d638173e7520 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Mon, 14 Aug 2017 08:54:57 +0100 Subject: [PATCH] Removed redundant .c_str()s from StringRef usages --- include/internal/catch_assertionhandler.cpp | 4 ++-- include/internal/catch_assertionresult.cpp | 19 +++++++++++++------ include/internal/catch_benchmark.h | 2 +- include/internal/catch_capture.hpp | 2 +- include/internal/catch_capture_matchers.h | 2 +- include/internal/catch_decomposer.h | 2 +- .../internal/catch_interfaces_reporter.cpp | 2 +- include/internal/catch_test_registry.cpp | 6 +++--- include/reporters/catch_reporter_console.cpp | 2 +- 9 files changed, 24 insertions(+), 17 deletions(-) diff --git a/include/internal/catch_assertionhandler.cpp b/include/internal/catch_assertionhandler.cpp index 9e7c8453..0eed7cd9 100644 --- a/include/internal/catch_assertionhandler.cpp +++ b/include/internal/catch_assertionhandler.cpp @@ -79,7 +79,7 @@ namespace Catch { } void AssertionHandler::handle( ResultWas::OfType resultType, StringRef const& message ) { AssertionResultData data( resultType, LazyExpression( false ) ); - data.message = message.c_str(); + data.message = message; handle( data, nullptr ); } void AssertionHandler::handle( ResultWas::OfType resultType, ITransientExpression const* expr, bool negated ) { @@ -126,7 +126,7 @@ namespace Catch { } void AssertionHandler::useActiveException() { - handle( ResultWas::ThrewException, Catch::translateActiveException().c_str() ); + handle( ResultWas::ThrewException, Catch::translateActiveException() ); } void AssertionHandler::setExceptionGuard() { diff --git a/include/internal/catch_assertionresult.cpp b/include/internal/catch_assertionresult.cpp index 04402000..776fdc72 100644 --- a/include/internal/catch_assertionresult.cpp +++ b/include/internal/catch_assertionresult.cpp @@ -52,16 +52,23 @@ namespace Catch { std::string AssertionResult::getExpression() const { if (isFalseTest(m_info.resultDisposition)) - return '!' + std::string(m_info.capturedExpression.c_str()); + return '!' + std::string(m_info.capturedExpression); else - return std::string(m_info.capturedExpression.c_str()); + return m_info.capturedExpression; } std::string AssertionResult::getExpressionInMacro() const { + std::string expr; if( m_info.macroName[0] == 0 ) - return std::string(m_info.capturedExpression.c_str()); - else - return std::string(m_info.macroName.c_str()) + "( " + m_info.capturedExpression.c_str() + " )"; + expr = m_info.capturedExpression; + else { + expr.reserve( m_info.macroName.size() + m_info.capturedExpression.size() + 4 ); + expr += m_info.macroName; + expr += "( "; + expr += m_info.capturedExpression; + expr += " )"; + } + return expr; } bool AssertionResult::hasExpandedExpression() const { @@ -83,7 +90,7 @@ namespace Catch { } std::string AssertionResult::getTestMacroName() const { - return m_info.macroName.c_str(); + return m_info.macroName; } } // end namespace Catch diff --git a/include/internal/catch_benchmark.h b/include/internal/catch_benchmark.h index ffb1db78..2e33c163 100644 --- a/include/internal/catch_benchmark.h +++ b/include/internal/catch_benchmark.h @@ -28,7 +28,7 @@ namespace Catch { public: // Keep most of this inline as it's on the code path that is being timed BenchmarkLooper( StringRef name ) - : m_name( name.c_str() ), + : m_name( name ), m_resolution( getResolution() ) { reportStart(); diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp index 2f631bd3..d5d0ad4e 100644 --- a/include/internal/catch_capture.hpp +++ b/include/internal/catch_capture.hpp @@ -126,7 +126,7 @@ #define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \ do { \ Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \ - catchAssertionHandler.handle( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str().c_str() ); \ + catchAssertionHandler.handle( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \ INTERNAL_CATCH_REACT( catchAssertionHandler ) \ } while( Catch::alwaysFalse() ) diff --git a/include/internal/catch_capture_matchers.h b/include/internal/catch_capture_matchers.h index e3e43568..f815c14e 100644 --- a/include/internal/catch_capture_matchers.h +++ b/include/internal/catch_capture_matchers.h @@ -35,7 +35,7 @@ namespace Catch { auto matcherAsString = m_matcher.toString(); os << Catch::Detail::stringify( m_arg ) << ' '; if( matcherAsString == Detail::unprintableString ) - os << m_matcherString.c_str(); + os << m_matcherString; else os << matcherAsString; } diff --git a/include/internal/catch_decomposer.h b/include/internal/catch_decomposer.h index e1c2f217..6d20be78 100644 --- a/include/internal/catch_decomposer.h +++ b/include/internal/catch_decomposer.h @@ -53,7 +53,7 @@ namespace Catch { BinaryExpr( bool comparisionResult, LhsT lhs, StringRef op, RhsT rhs ) : m_result( comparisionResult ), m_lhs( lhs ), - m_op( op.c_str() ), + m_op( op ), m_rhs( rhs ) {} }; diff --git a/include/internal/catch_interfaces_reporter.cpp b/include/internal/catch_interfaces_reporter.cpp index 05117f9e..c7b2e861 100644 --- a/include/internal/catch_interfaces_reporter.cpp +++ b/include/internal/catch_interfaces_reporter.cpp @@ -42,7 +42,7 @@ namespace Catch { if( assertionResult.hasMessage() ) { // Copy message into messages list. // !TBD This should have been done earlier, somewhere - MessageBuilder builder( assertionResult.getTestMacroName().c_str(), assertionResult.getSourceInfo(), assertionResult.getResultType() ); + MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() ); builder << assertionResult.getMessage(); builder.m_info.message = builder.m_stream.str(); diff --git a/include/internal/catch_test_registry.cpp b/include/internal/catch_test_registry.cpp index 2862879c..7a796cce 100644 --- a/include/internal/catch_test_registry.cpp +++ b/include/internal/catch_test_registry.cpp @@ -23,9 +23,9 @@ namespace Catch { .registerTest( makeTestCase( invoker, - extractClassName( classOrMethod.c_str() ), - nameAndTags.name.c_str(), - nameAndTags.tags.c_str(), + extractClassName( classOrMethod ), + nameAndTags.name, + nameAndTags.tags, lineInfo)); } catch (...) { // Do not throw when constructing global objects, instead register the exception to be processed later diff --git a/include/reporters/catch_reporter_console.cpp b/include/reporters/catch_reporter_console.cpp index ca102df6..0922134d 100644 --- a/include/reporters/catch_reporter_console.cpp +++ b/include/reporters/catch_reporter_console.cpp @@ -85,7 +85,7 @@ namespace { friend TablePrinter& operator << ( TablePrinter& tp, ColumnBreak ) { auto colStr = tp.m_oss.str(); // This takes account of utf8 encodings - auto strSize = Catch::StringRef( colStr.c_str(), colStr.size() ).numberOfCharacters(); + auto strSize = Catch::StringRef( colStr ).numberOfCharacters(); tp.m_oss.str(""); tp.open(); if( tp.m_currentColumn == static_cast(tp.m_columnInfos.size()-1) ) {