mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 20:27:11 +01:00 
			
		
		
		
	Avoid copying StringRef
In theory the copy is cheap (couple of pointers change), but tests are usually compiled in Debug mode/with minimal optimizations, which means that most users will still have to pay the cost for those function calls.
This commit is contained in:
		| @@ -52,7 +52,7 @@ namespace Catch { | ||||
|     } | ||||
|  | ||||
|     AssertionHandler::AssertionHandler | ||||
|         (   StringRef macroName, | ||||
|         (   StringRef const& macroName, | ||||
|             SourceLineInfo const& lineInfo, | ||||
|             StringRef capturedExpression, | ||||
|             ResultDisposition::Flags resultDisposition ) | ||||
| @@ -109,7 +109,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 matcherString  ) { | ||||
|     void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef const& matcherString  ) { | ||||
|         handleExceptionMatchExpr( handler, Matchers::Equals( str ), matcherString ); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -49,7 +49,7 @@ namespace Catch { | ||||
|  | ||||
|     public: | ||||
|         AssertionHandler | ||||
|             (   StringRef macroName, | ||||
|             (   StringRef const& macroName, | ||||
|                 SourceLineInfo const& lineInfo, | ||||
|                 StringRef capturedExpression, | ||||
|                 ResultDisposition::Flags resultDisposition ); | ||||
| @@ -81,7 +81,7 @@ namespace Catch { | ||||
|         auto allowThrows() const -> bool; | ||||
|     }; | ||||
|  | ||||
|     void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ); | ||||
|     void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef const& matcherString ); | ||||
|  | ||||
| } // namespace Catch | ||||
|  | ||||
|   | ||||
| @@ -15,7 +15,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 matcherString  ) { | ||||
|     void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString  ) { | ||||
|         std::string exceptionMessage = Catch::translateActiveException(); | ||||
|         MatchExpr<std::string, StringMatcher const&> expr( exceptionMessage, matcher, matcherString ); | ||||
|         handler.handleExpr( expr ); | ||||
|   | ||||
| @@ -24,7 +24,7 @@ namespace Catch { | ||||
|         MatcherT m_matcher; | ||||
|         StringRef m_matcherString; | ||||
|     public: | ||||
|         MatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef matcherString ) | ||||
|         MatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef const& matcherString ) | ||||
|         :   ITransientExpression{ true, matcher.match( arg ) }, | ||||
|             m_arg( arg ), | ||||
|             m_matcher( matcher ), | ||||
| @@ -43,10 +43,10 @@ namespace Catch { | ||||
|  | ||||
|     using StringMatcher = Matchers::Impl::MatcherBase<std::string>; | ||||
|  | ||||
|     void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString  ); | ||||
|     void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString  ); | ||||
|  | ||||
|     template<typename ArgT, typename MatcherT> | ||||
|     auto makeMatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef matcherString  ) -> MatchExpr<ArgT, MatcherT> { | ||||
|     auto makeMatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef const& matcherString  ) -> MatchExpr<ArgT, MatcherT> { | ||||
|         return MatchExpr<ArgT, MatcherT>( arg, matcher, matcherString ); | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Martin Hořeňovský
					Martin Hořeňovský