diff options
| author | Martin Hořeňovský | 2020-12-04 21:37:19 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2020-12-04 21:37:24 +0100 |
| commit | 6350851f9af96a1c35da92b18ca7cb3d90fa67c9 (patch) | |
| tree | 783930500698885dbe66e96d8012a6d3fd577f86 /src/catch2/internal/catch_run_context.cpp | |
| parent | 21c97f2fad9ab9c979b7d1065253bbb4b172b6dc (diff) | |
| download | catch3-6350851f9af96a1c35da92b18ca7cb3d90fa67c9.tar.gz | |
Return plain ptr from ITracker::findChild instead of shared_ptr
This is part of wider rework of trackers to avoid `std::shared_ptr`
everywhere.
Related to #2088
Diffstat (limited to 'src/catch2/internal/catch_run_context.cpp')
| -rw-r--r-- | src/catch2/internal/catch_run_context.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp index 777c7075..79022dd4 100644 --- a/src/catch2/internal/catch_run_context.cpp +++ b/src/catch2/internal/catch_run_context.cpp @@ -34,7 +34,7 @@ namespace Catch { ~GeneratorTracker(); static GeneratorTracker& acquire( TrackerContext& ctx, TestCaseTracking::NameAndLocation const& nameAndLocation ) { - std::shared_ptr<GeneratorTracker> tracker; + GeneratorTracker* tracker; ITracker& currentTracker = ctx.currentTracker(); // Under specific circumstances, the generator we want @@ -48,18 +48,22 @@ namespace Catch { // } // // without it, the code above creates 5 nested generators. - if (currentTracker.nameAndLocation() == nameAndLocation) { - auto thisTracker = currentTracker.parent().findChild(nameAndLocation); - assert(thisTracker); - assert(thisTracker->isGeneratorTracker()); - tracker = std::static_pointer_cast<GeneratorTracker>(thisTracker); - } else if ( TestCaseTracking::ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) { + if ( currentTracker.nameAndLocation() == nameAndLocation ) { + auto thisTracker = + currentTracker.parent().findChild( nameAndLocation ); + assert( thisTracker ); + assert( thisTracker->isGeneratorTracker() ); + tracker = static_cast<GeneratorTracker*>( thisTracker ); + } else if ( ITracker* childTracker = + currentTracker.findChild( nameAndLocation ) ) { assert( childTracker ); assert( childTracker->isGeneratorTracker() ); - tracker = std::static_pointer_cast<GeneratorTracker>( childTracker ); + tracker = static_cast<GeneratorTracker*>( childTracker ); } else { - tracker = std::make_shared<GeneratorTracker>( nameAndLocation, ctx, ¤tTracker ); - currentTracker.addChild( tracker ); + auto newTracker = std::make_shared<GeneratorTracker>( + nameAndLocation, ctx, ¤tTracker ); + tracker = newTracker.get(); + currentTracker.addChild( std::move(newTracker) ); } if( !tracker->isComplete() ) { |