Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorMartin Hořeňovský2018-03-02 16:22:18 +0100
committerMartin Hořeňovský2018-03-02 16:24:35 +0100
commitd2ddb997a74f698e10ac3debbfc48b3722caf3eb (patch)
tree42a8ad3a4ecaaaf63810e8053182155da0d4ac7f /include
parent865d5f59b49c3e823c471dc2022116a10f33b0c4 (diff)
downloadcatch3-d2ddb997a74f698e10ac3debbfc48b3722caf3eb.tar.gz
Cleanup for performance reasons
* Eliminated some copies * Made makeTestCase fit into 4 arguments -- avoids spills on Win64 * Made string literals into StringRef literals
Diffstat (limited to 'include')
-rw-r--r--include/internal/catch_run_context.cpp6
-rw-r--r--include/internal/catch_test_case_info.cpp10
-rw-r--r--include/internal/catch_test_case_info.h6
-rw-r--r--include/internal/catch_test_case_registry_impl.cpp2
-rw-r--r--include/internal/catch_test_case_registry_impl.h4
-rw-r--r--include/internal/catch_test_registry.cpp9
-rw-r--r--include/internal/catch_test_registry.h4
7 files changed, 20 insertions, 21 deletions
diff --git a/include/internal/catch_run_context.cpp b/include/internal/catch_run_context.cpp
index ca78bfb4..99c77058 100644
--- a/include/internal/catch_run_context.cpp
+++ b/include/internal/catch_run_context.cpp
@@ -57,7 +57,7 @@ namespace Catch {
m_context(getCurrentMutableContext()),
m_config(_config),
m_reporter(std::move(reporter)),
- m_lastAssertionInfo{ "", SourceLineInfo("",0), "", ResultDisposition::Normal },
+ m_lastAssertionInfo{ StringRef(), SourceLineInfo("",0), StringRef(), ResultDisposition::Normal },
m_includeSuccessfulResults( m_config->includeSuccessfulResults() )
{
m_context.setRunner(this);
@@ -84,7 +84,7 @@ namespace Catch {
std::string redirectedCout;
std::string redirectedCerr;
- TestCaseInfo testInfo = testCase.getTestCaseInfo();
+ auto const& testInfo = testCase.getTestCaseInfo();
m_reporter->testCaseStarting(testInfo);
@@ -292,7 +292,7 @@ namespace Catch {
Counts prevAssertions = m_totals.assertions;
double duration = 0;
m_shouldReportUnexpected = true;
- m_lastAssertionInfo = { "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal };
+ m_lastAssertionInfo = { "TEST_CASE"_sr, testCaseInfo.lineInfo, StringRef(), ResultDisposition::Normal };
seedRng(*m_config);
diff --git a/include/internal/catch_test_case_info.cpp b/include/internal/catch_test_case_info.cpp
index 4ab97755..9bf68912 100644
--- a/include/internal/catch_test_case_info.cpp
+++ b/include/internal/catch_test_case_info.cpp
@@ -48,8 +48,7 @@ namespace Catch {
TestCase makeTestCase( ITestInvoker* _testCase,
std::string const& _className,
- std::string const& _name,
- std::string const& _descOrTags,
+ NameAndTags const& nameAndTags,
SourceLineInfo const& _lineInfo )
{
bool isHidden = false;
@@ -58,6 +57,7 @@ namespace Catch {
std::vector<std::string> tags;
std::string desc, tag;
bool inTag = false;
+ std::string _descOrTags = nameAndTags.tags;
for (char c : _descOrTags) {
if( !inTag ) {
if( c == '[' )
@@ -85,8 +85,8 @@ namespace Catch {
tags.push_back( "." );
}
- TestCaseInfo info( _name, _className, desc, tags, _lineInfo );
- return TestCase( _testCase, info );
+ TestCaseInfo info( nameAndTags.name, _className, desc, tags, _lineInfo );
+ return TestCase( _testCase, std::move(info) );
}
void setTags( TestCaseInfo& testCaseInfo, std::vector<std::string> tags ) {
@@ -147,7 +147,7 @@ namespace Catch {
}
- TestCase::TestCase( ITestInvoker* testCase, TestCaseInfo const& info ) : TestCaseInfo( info ), test( testCase ) {}
+ TestCase::TestCase( ITestInvoker* testCase, TestCaseInfo&& info ) : TestCaseInfo( std::move(info) ), test( testCase ) {}
TestCase TestCase::withName( std::string const& _newName ) const {
diff --git a/include/internal/catch_test_case_info.h b/include/internal/catch_test_case_info.h
index 2a911b06..809c974f 100644
--- a/include/internal/catch_test_case_info.h
+++ b/include/internal/catch_test_case_info.h
@@ -9,6 +9,7 @@
#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED
#include "catch_common.h"
+#include "catch_test_registry.h"
#include <string>
#include <vector>
@@ -61,7 +62,7 @@ namespace Catch {
class TestCase : public TestCaseInfo {
public:
- TestCase( ITestInvoker* testCase, TestCaseInfo const& info );
+ TestCase( ITestInvoker* testCase, TestCaseInfo&& info );
TestCase withName( std::string const& _newName ) const;
@@ -78,8 +79,7 @@ namespace Catch {
TestCase makeTestCase( ITestInvoker* testCase,
std::string const& className,
- std::string const& name,
- std::string const& description,
+ NameAndTags const& nameAndTags,
SourceLineInfo const& lineInfo );
}
diff --git a/include/internal/catch_test_case_registry_impl.cpp b/include/internal/catch_test_case_registry_impl.cpp
index 89c72392..b30b112a 100644
--- a/include/internal/catch_test_case_registry_impl.cpp
+++ b/include/internal/catch_test_case_registry_impl.cpp
@@ -96,7 +96,7 @@ namespace Catch {
m_testAsFunction();
}
- std::string extractClassName( std::string const& classOrQualifiedMethodName ) {
+ std::string extractClassName( StringRef const& classOrQualifiedMethodName ) {
std::string className = classOrQualifiedMethodName;
if( startsWith( className, '&' ) )
{
diff --git a/include/internal/catch_test_case_registry_impl.h b/include/internal/catch_test_case_registry_impl.h
index ad45e5a0..8dc5b0fe 100644
--- a/include/internal/catch_test_case_registry_impl.h
+++ b/include/internal/catch_test_case_registry_impl.h
@@ -22,7 +22,7 @@ namespace Catch {
class TestCase;
struct IConfig;
- std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases );
+ std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases );
bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config );
void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions );
@@ -58,7 +58,7 @@ namespace Catch {
};
- std::string extractClassName( std::string const& classOrQualifiedMethodName );
+ std::string extractClassName( StringRef const& classOrQualifiedMethodName );
///////////////////////////////////////////////////////////////////////////
diff --git a/include/internal/catch_test_registry.cpp b/include/internal/catch_test_registry.cpp
index ec50e92c..ac83f333 100644
--- a/include/internal/catch_test_registry.cpp
+++ b/include/internal/catch_test_registry.cpp
@@ -15,23 +15,22 @@ namespace Catch {
return new(std::nothrow) TestInvokerAsFunction( testAsFunction );
}
- NameAndTags::NameAndTags( StringRef name_ , StringRef tags_ ) noexcept : name( name_ ), tags( tags_ ) {}
+ NameAndTags::NameAndTags( StringRef const& name_ , StringRef const& tags_ ) noexcept : name( name_ ), tags( tags_ ) {}
- AutoReg::AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept {
+ AutoReg::AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept {
try {
getMutableRegistryHub()
.registerTest(
makeTestCase(
invoker,
extractClassName( classOrMethod ),
- nameAndTags.name,
- nameAndTags.tags,
+ nameAndTags,
lineInfo));
} catch (...) {
// Do not throw when constructing global objects, instead register the exception to be processed later
getMutableRegistryHub().registerStartupException();
}
}
-
+
AutoReg::~AutoReg() = default;
}
diff --git a/include/internal/catch_test_registry.h b/include/internal/catch_test_registry.h
index 84001018..a192a531 100644
--- a/include/internal/catch_test_registry.h
+++ b/include/internal/catch_test_registry.h
@@ -35,13 +35,13 @@ auto makeTestInvoker( void (C::*testAsMethod)() ) noexcept -> ITestInvoker* {
}
struct NameAndTags {
- NameAndTags( StringRef name_ = StringRef(), StringRef tags_ = StringRef() ) noexcept;
+ NameAndTags( StringRef const& name_ = StringRef(), StringRef const& tags_ = StringRef() ) noexcept;
StringRef name;
StringRef tags;
};
struct AutoReg : NonCopyable {
- AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept;
+ AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept;
~AutoReg();
};