Pass other StringRef arguments by value instead of by-ref

Apart from being clearer, it also improves the overall codesize
of the implementation library, and should improve the performance
as well, by removing one level of indirection.
This commit is contained in:
Martin Hořeňovský 2021-05-14 23:45:59 +02:00
parent 074017f5ad
commit 61e16416a9
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
11 changed files with 19 additions and 19 deletions

View File

@ -63,7 +63,7 @@ namespace Catch {
virtual void handleMessage
( AssertionInfo const& info,
ResultWas::OfType resultType,
StringRef const& message,
StringRef message,
AssertionReaction& reaction ) = 0;
virtual void handleUnexpectedExceptionNotThrown
( AssertionInfo const& info,

View File

@ -18,7 +18,7 @@
namespace Catch {
AssertionHandler::AssertionHandler
( StringRef const& macroName,
( StringRef macroName,
SourceLineInfo const& lineInfo,
StringRef capturedExpression,
ResultDisposition::Flags resultDisposition )
@ -29,7 +29,7 @@ namespace Catch {
void AssertionHandler::handleExpr( ITransientExpression const& expr ) {
m_resultCapture.handleExpr( m_assertionInfo, expr, m_reaction );
}
void AssertionHandler::handleMessage(ResultWas::OfType resultType, StringRef const& message) {
void AssertionHandler::handleMessage(ResultWas::OfType resultType, StringRef message) {
m_resultCapture.handleMessage( m_assertionInfo, resultType, message, m_reaction );
}
@ -80,7 +80,7 @@ namespace Catch {
// This is the overload that takes a string and infers the Equals matcher from it
// The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp
void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef const& matcherString ) {
void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ) {
handleExceptionMatchExpr( handler, Matchers::Equals( str ), matcherString );
}

View File

@ -32,7 +32,7 @@ namespace Catch {
public:
AssertionHandler
( StringRef const& macroName,
( StringRef macroName,
SourceLineInfo const& lineInfo,
StringRef capturedExpression,
ResultDisposition::Flags resultDisposition );
@ -49,7 +49,7 @@ namespace Catch {
}
void handleExpr( ITransientExpression const& expr );
void handleMessage(ResultWas::OfType resultType, StringRef const& message);
void handleMessage(ResultWas::OfType resultType, StringRef message);
void handleExceptionThrownAsExpected();
void handleUnexpectedExceptionNotThrown();
@ -64,7 +64,7 @@ namespace Catch {
auto allowThrows() const -> bool;
};
void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef const& matcherString );
void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString );
} // namespace Catch

View File

@ -519,7 +519,7 @@ namespace Catch {
void RunContext::handleMessage(
AssertionInfo const& info,
ResultWas::OfType resultType,
StringRef const& message,
StringRef message,
AssertionReaction& reaction
) {
m_reporter->assertionStarting( info );

View File

@ -54,7 +54,7 @@ namespace Catch {
void handleMessage
( AssertionInfo const& info,
ResultWas::OfType resultType,
StringRef const& message,
StringRef message,
AssertionReaction& reaction ) override;
void handleUnexpectedExceptionNotThrown
( AssertionInfo const& info,

View File

@ -149,7 +149,7 @@ namespace {
m_testAsFunction();
}
std::string extractClassName( StringRef const& classOrQualifiedMethodName ) {
std::string extractClassName( StringRef classOrQualifiedMethodName ) {
std::string className(classOrQualifiedMethodName);
if( startsWith( className, '&' ) )
{

View File

@ -64,7 +64,7 @@ namespace Catch {
};
std::string extractClassName( StringRef const& classOrQualifiedMethodName );
std::string extractClassName( StringRef classOrQualifiedMethodName );
///////////////////////////////////////////////////////////////////////////

View File

@ -17,7 +17,7 @@ namespace Catch {
return Detail::unique_ptr<ITestInvoker>( new TestInvokerAsFunction( testAsFunction ));
}
AutoReg::AutoReg( Detail::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept {
AutoReg::AutoReg( Detail::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept {
CATCH_TRY {
getMutableRegistryHub()
.registerTest(

View File

@ -46,15 +46,15 @@ Detail::unique_ptr<ITestInvoker> makeTestInvoker( void (C::*testAsMethod)() ) {
}
struct NameAndTags {
NameAndTags(StringRef const& name_ = StringRef(),
StringRef const& tags_ = StringRef()) noexcept:
NameAndTags(StringRef name_ = StringRef(),
StringRef tags_ = StringRef()) noexcept:
name(name_), tags(tags_) {}
StringRef name;
StringRef tags;
};
struct AutoReg : Detail::NonCopyable {
AutoReg( Detail::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept;
AutoReg( Detail::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept;
};
} // end namespace Catch

View File

@ -29,7 +29,7 @@ namespace Catch {
// This is the general overload that takes a any string matcher
// There is another overload, in catch_assertionhandler.h/.cpp, that only takes a string and infers
// the Equals matcher (so the header does not mention matchers)
void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString ) {
void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString ) {
std::string exceptionMessage = Catch::translateActiveException();
MatchExpr<std::string, StringMatcher const&> expr( std::move(exceptionMessage), matcher, matcherString );
handler.handleExpr( expr );

View File

@ -19,7 +19,7 @@ namespace Catch {
MatcherT const& m_matcher;
StringRef m_matcherString;
public:
MatchExpr( ArgT && arg, MatcherT const& matcher, StringRef const& matcherString )
MatchExpr( ArgT && arg, MatcherT const& matcher, StringRef matcherString )
: ITransientExpression{ true, matcher.match( arg ) }, // not forwarding arg here on purpose
m_arg( std::forward<ArgT>(arg) ),
m_matcher( matcher ),
@ -43,10 +43,10 @@ namespace Catch {
using StringMatcher = Matchers::MatcherBase<std::string>;
void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString );
void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString );
template<typename ArgT, typename MatcherT>
auto makeMatchExpr( ArgT && arg, MatcherT const& matcher, StringRef const& matcherString ) -> MatchExpr<ArgT, MatcherT> {
auto makeMatchExpr( ArgT && arg, MatcherT const& matcher, StringRef matcherString ) -> MatchExpr<ArgT, MatcherT> {
return MatchExpr<ArgT, MatcherT>( std::forward<ArgT>(arg), matcher, matcherString );
}