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.
This commit is contained in:
Martin Hořeňovský 2018-07-23 13:42:44 +02:00
parent b93284716e
commit 78804ea304
2 changed files with 6 additions and 5 deletions

View File

@ -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) {}

View File

@ -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 );