Do not copy around TestCaseInfo

Now a `TEST_CASE` macro should create a single TestCaseInfo and then
it should never be copied around. This, together with latter changes,
should significantly decrease the number of allocations made before
`main` is even entered.
This commit is contained in:
Martin Hořeňovský
2019-11-14 10:52:34 +01:00
parent 019b0a0fe0
commit 302e2c0b06
33 changed files with 631 additions and 626 deletions
+14 -22
View File
@@ -53,10 +53,10 @@ namespace Catch {
}
}
TestCase makeTestCase( ITestInvoker* _testCase,
std::string const& _className,
NameAndTags const& nameAndTags,
SourceLineInfo const& _lineInfo )
std::unique_ptr<TestCaseInfo>
makeTestCaseInfo(std::string const& _className,
NameAndTags const& nameAndTags,
SourceLineInfo const& _lineInfo )
{
bool isHidden = false;
@@ -95,8 +95,8 @@ namespace Catch {
tags.push_back( "." );
}
TestCaseInfo info( static_cast<std::string>(nameAndTags.name), _className, tags, _lineInfo );
return TestCase( _testCase, std::move(info) );
return std::make_unique<TestCaseInfo>(static_cast<std::string>(nameAndTags.name),
_className, tags, _lineInfo);
}
void setTags( TestCaseInfo& testCaseInfo, std::vector<std::string> tags ) {
@@ -155,26 +155,18 @@ namespace Catch {
}
TestCase::TestCase( ITestInvoker* testCase, TestCaseInfo&& info ) : TestCaseInfo( std::move(info) ), test( testCase ) {}
void TestCase::invoke() const {
test->invoke();
bool TestCaseHandle::operator == ( TestCaseHandle const& rhs ) const {
return m_invoker == rhs.m_invoker
&& m_info->name == rhs.m_info->name
&& m_info->className == rhs.m_info->className;
}
bool TestCase::operator == ( TestCase const& other ) const {
return test.get() == other.test.get() &&
name == other.name &&
className == other.className;
bool TestCaseHandle::operator < ( TestCaseHandle const& rhs ) const {
return m_info->name < rhs.m_info->name;
}
bool TestCase::operator < ( TestCase const& other ) const {
return name < other.name;
}
TestCaseInfo const& TestCase::getTestCaseInfo() const
{
return *this;
TestCaseInfo const& TestCaseHandle::getTestCaseInfo() const {
return *m_info;
}
} // end namespace Catch