Avoid allocating trimmed name for SectionTracker

This commit is contained in:
Martin Hořeňovský 2023-02-20 00:12:54 +01:00
parent 0477326ad9
commit fed1436246
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
2 changed files with 6 additions and 2 deletions

View File

@ -163,7 +163,7 @@ namespace TestCaseTracking {
SectionTracker::SectionTracker( NameAndLocation&& nameAndLocation, TrackerContext& ctx, ITracker* parent )
: TrackerBase( CATCH_MOVE(nameAndLocation), ctx, parent ),
m_trimmed_name(trim(ITracker::nameAndLocation().name))
m_trimmed_name(trim(StringRef(ITracker::nameAndLocation().name)))
{
if( parent ) {
while ( !parent->isSectionTracker() ) {

View File

@ -195,7 +195,11 @@ namespace TestCaseTracking {
class SectionTracker : public TrackerBase {
std::vector<StringRef> m_filters;
std::string m_trimmed_name;
// Note that lifetime-wise we piggy back off the name stored in the `ITracker` parent`.
// Currently it allocates owns the name, so this is safe. If it is later refactored
// to not own the name, the name still has to outlive the `ITracker` parent, so
// this should still be safe.
StringRef m_trimmed_name;
public:
SectionTracker( NameAndLocation&& nameAndLocation, TrackerContext& ctx, ITracker* parent );