1
0
mirror of https://github.com/catchorg/Catch2.git synced 2025-01-16 15:18:00 +00:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Martin Hořeňovský
d218d6f9e2
Avoid recalculating string-literal size on root tracker construction
This is a tiiiiiiny performance optimization, but it's free.
2020-07-27 20:08:44 +02:00
Martin Hořeňovský
ef92178058
Devirtualize nested tracker handling 2020-07-27 19:53:54 +02:00
2 changed files with 38 additions and 29 deletions

View File

@ -31,9 +31,27 @@ namespace TestCaseTracking {
ITracker::~ITracker() = default;
void ITracker::addChild( ITrackerPtr const& child ) {
m_children.push_back( child );
}
ITrackerPtr ITracker::findChild( NameAndLocation const& nameAndLocation ) {
auto it = std::find_if(
m_children.begin(),
m_children.end(),
[&nameAndLocation]( ITrackerPtr const& tracker ) {
return tracker->nameAndLocation().location ==
nameAndLocation.location &&
tracker->nameAndLocation().name == nameAndLocation.name;
} );
return ( it != m_children.end() ) ? *it : nullptr;
}
ITracker& TrackerContext::startRun() {
m_rootTracker = std::make_shared<SectionTracker>( NameAndLocation( "{root}", CATCH_INTERNAL_LINEINFO ), *this, nullptr );
using namespace std::string_literals;
m_rootTracker = std::make_shared<SectionTracker>( NameAndLocation( "{root}"s, CATCH_INTERNAL_LINEINFO ), *this, nullptr );
m_currentTracker = nullptr;
m_runState = Executing;
return *m_rootTracker;
@ -79,26 +97,7 @@ namespace TestCaseTracking {
bool TrackerBase::isOpen() const {
return m_runState != NotStarted && !isComplete();
}
bool TrackerBase::hasChildren() const {
return !m_children.empty();
}
void TrackerBase::addChild( ITrackerPtr const& child ) {
m_children.push_back( child );
}
ITrackerPtr TrackerBase::findChild( NameAndLocation const& nameAndLocation ) {
auto it = std::find_if( m_children.begin(), m_children.end(),
[&nameAndLocation]( ITrackerPtr const& tracker ){
return
tracker->nameAndLocation().location == nameAndLocation.location &&
tracker->nameAndLocation().name == nameAndLocation.name;
} );
return( it != m_children.end() )
? *it
: nullptr;
}
ITracker& TrackerBase::parent() {
assert( m_parent ); // Should always be non-null except for root
return *m_parent;

View File

@ -36,6 +36,11 @@ namespace TestCaseTracking {
class ITracker {
NameAndLocation m_nameAndLocation;
using Children = std::vector<ITrackerPtr>;
protected:
Children m_children;
public:
ITracker(NameAndLocation const& nameAndLoc) :
m_nameAndLocation(nameAndLoc)
@ -54,7 +59,6 @@ namespace TestCaseTracking {
virtual bool isComplete() const = 0; // Successfully completed or failed
virtual bool isSuccessfullyCompleted() const = 0;
virtual bool isOpen() const = 0; // Started but not complete
virtual bool hasChildren() const = 0;
virtual bool hasStarted() const = 0;
virtual ITracker& parent() = 0;
@ -64,8 +68,20 @@ namespace TestCaseTracking {
virtual void fail() = 0;
virtual void markAsNeedingAnotherRun() = 0;
virtual void addChild( ITrackerPtr const& child ) = 0;
virtual ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) = 0;
//! Register a nested ITracker
void addChild( ITrackerPtr const& child );
/**
* Returns ptr to specific child if register with this tracker.
*
* Returns nullptr if not found.
*/
ITrackerPtr findChild( NameAndLocation const& nameAndLocation );
//! Have any children been added?
bool hasChildren() const {
return !m_children.empty();
}
virtual void openChild() = 0;
// Debug/ checking
@ -109,10 +125,8 @@ namespace TestCaseTracking {
Failed
};
using Children = std::vector<ITrackerPtr>;
TrackerContext& m_ctx;
ITracker* m_parent;
Children m_children;
CycleState m_runState = NotStarted;
public:
@ -121,14 +135,10 @@ namespace TestCaseTracking {
bool isComplete() const override;
bool isSuccessfullyCompleted() const override;
bool isOpen() const override;
bool hasChildren() const override;
bool hasStarted() const override {
return m_runState != NotStarted;
}
void addChild( ITrackerPtr const& child ) override;
ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) override;
ITracker& parent() override;
void openChild() override;