From 78804ea304167f15fd2362b15494be358361a922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Mon, 23 Jul 2018 13:42:44 +0200 Subject: [PATCH] Replace std::string with StringRef in MessageInfo for macro capture Because the macro name is compile-time constant, we do not have to worry about lifetimes and will avoid allocation in case of missing SSO or long macro name. --- include/internal/catch_message.cpp | 4 ++-- include/internal/catch_message.h | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/internal/catch_message.cpp b/include/internal/catch_message.cpp index 8684970a..89fa96d8 100644 --- a/include/internal/catch_message.cpp +++ b/include/internal/catch_message.cpp @@ -12,7 +12,7 @@ namespace Catch { - MessageInfo::MessageInfo( std::string const& _macroName, + MessageInfo::MessageInfo( StringRef const& _macroName, SourceLineInfo const& _lineInfo, ResultWas::OfType _type ) : macroName( _macroName ), @@ -35,7 +35,7 @@ namespace Catch { //////////////////////////////////////////////////////////////////////////// - Catch::MessageBuilder::MessageBuilder( std::string const& macroName, + Catch::MessageBuilder::MessageBuilder( StringRef const& macroName, SourceLineInfo const& lineInfo, ResultWas::OfType type ) :m_info(macroName, lineInfo, type) {} diff --git a/include/internal/catch_message.h b/include/internal/catch_message.h index 0a512ed5..96f098f6 100644 --- a/include/internal/catch_message.h +++ b/include/internal/catch_message.h @@ -12,15 +12,16 @@ #include "catch_result_type.h" #include "catch_common.h" #include "catch_stream.h" +#include "catch_stringref.h" namespace Catch { struct MessageInfo { - MessageInfo( std::string const& _macroName, + MessageInfo( StringRef const& _macroName, SourceLineInfo const& _lineInfo, ResultWas::OfType _type ); - std::string macroName; + StringRef macroName; std::string message; SourceLineInfo lineInfo; ResultWas::OfType type; @@ -44,7 +45,7 @@ namespace Catch { }; struct MessageBuilder : MessageStream { - MessageBuilder( std::string const& macroName, + MessageBuilder( StringRef const& macroName, SourceLineInfo const& lineInfo, ResultWas::OfType type );