Skip to content

Commit

Permalink
Avoid copying NameAndLocationRef when passed as argument
Browse files Browse the repository at this point in the history
`NameAndLocationRef` is pretty large type, so even in release build,
it is unlikely to be passed in registers. In addition to the fact
that some platforms currently do not allow passing even small types
in register (Windows ABI!!), it is better to pass it as a ref,
effectively passing around a pointer.
  • Loading branch information
horenmar committed Feb 20, 2023
1 parent e1dbad4 commit 4f7c8cb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/catch2/internal/catch_run_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Catch {
{}
~GeneratorTracker() override;

static GeneratorTracker* acquire( TrackerContext& ctx, TestCaseTracking::NameAndLocationRef nameAndLocation ) {
static GeneratorTracker* acquire( TrackerContext& ctx, TestCaseTracking::NameAndLocationRef const& nameAndLocation ) {
GeneratorTracker* tracker;

ITracker& currentTracker = ctx.currentTracker();
Expand Down
4 changes: 2 additions & 2 deletions src/catch2/internal/catch_test_case_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace TestCaseTracking {
m_children.push_back( CATCH_MOVE(child) );
}

ITracker* ITracker::findChild( NameAndLocationRef nameAndLocation ) {
ITracker* ITracker::findChild( NameAndLocationRef const& nameAndLocation ) {
auto it = std::find_if(
m_children.begin(),
m_children.end(),
Expand Down Expand Up @@ -177,7 +177,7 @@ namespace TestCaseTracking {

bool SectionTracker::isSectionTracker() const { return true; }

SectionTracker& SectionTracker::acquire( TrackerContext& ctx, NameAndLocationRef nameAndLocation ) {
SectionTracker& SectionTracker::acquire( TrackerContext& ctx, NameAndLocationRef const& nameAndLocation ) {
SectionTracker* tracker;

ITracker& currentTracker = ctx.currentTracker();
Expand Down
8 changes: 4 additions & 4 deletions src/catch2/internal/catch_test_case_tracker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ namespace TestCaseTracking {
name( name_ ), location( location_ ) {}

friend bool operator==( NameAndLocation const& lhs,
NameAndLocationRef rhs ) {
NameAndLocationRef const& rhs ) {
return StringRef( lhs.name ) == rhs.name &&
lhs.location == rhs.location;
}
friend bool operator==( NameAndLocationRef lhs,
friend bool operator==( NameAndLocationRef const& lhs,
NameAndLocation const& rhs ) {
return rhs == lhs;
}
Expand Down Expand Up @@ -125,7 +125,7 @@ namespace TestCaseTracking {
*
* Returns nullptr if not found.
*/
ITracker* findChild( NameAndLocationRef nameAndLocation );
ITracker* findChild( NameAndLocationRef const& nameAndLocation );
//! Have any children been added?
bool hasChildren() const {
return !m_children.empty();
Expand Down Expand Up @@ -212,7 +212,7 @@ namespace TestCaseTracking {

bool isComplete() const override;

static SectionTracker& acquire( TrackerContext& ctx, NameAndLocationRef nameAndLocation );
static SectionTracker& acquire( TrackerContext& ctx, NameAndLocationRef const& nameAndLocation );

void tryOpen();

Expand Down

0 comments on commit 4f7c8cb

Please sign in to comment.