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

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2/internal
diff options
context:
space:
mode:
authorMartin Hořeňovský2020-05-25 09:45:24 +0200
committerMartin Hořeňovský2020-05-31 15:20:24 +0200
commit1d1ccf8f3c0c9e121b16afd4fafb850d14ef9fb0 (patch)
tree0a292cf929c75743993d42453312e08888ef7c0a /src/catch2/internal
parent41bbaa6d573a598fe0796fd0e391ed57eae62e30 (diff)
downloadcatch3-1d1ccf8f3c0c9e121b16afd4fafb850d14ef9fb0.tar.gz
Replace all uses of std::unique_ptr with Catch::Detail::unique_ptr
Doing some benchmarking with ClangBuildAnalyzer suggests that compiling Catch2's `SelfTest` spends 10% of the time instantiating `std::unique_ptr` for some interface types required for registering and running tests. The lesser compilation overhead of `Catch::Detail::unique_ptr` should significantly reduce that time. The compiled implementation was also changed to use the custom impl, to avoid having to convert between using `std::unique_ptr` and `Catch::Detail::unique_ptr`. This will likely also improve the compile times of the implementation, but that is less important than improving compilation times of the user's TUs with tests.
Diffstat (limited to 'src/catch2/internal')
-rw-r--r--src/catch2/internal/catch_enum_values_registry.cpp4
-rw-r--r--src/catch2/internal/catch_enum_values_registry.hpp6
-rw-r--r--src/catch2/internal/catch_exception_translator_registry.cpp2
-rw-r--r--src/catch2/internal/catch_exception_translator_registry.hpp3
-rw-r--r--src/catch2/internal/catch_reporter_registry.cpp16
-rw-r--r--src/catch2/internal/catch_stream.cpp16
-rw-r--r--src/catch2/internal/catch_template_test_registry.hpp2
-rw-r--r--src/catch2/internal/catch_test_case_registry_impl.cpp9
-rw-r--r--src/catch2/internal/catch_test_case_registry_impl.hpp12
-rw-r--r--src/catch2/internal/catch_test_registry.cpp9
-rw-r--r--src/catch2/internal/catch_test_registry.hpp11
-rw-r--r--src/catch2/internal/catch_test_spec_parser.cpp16
12 files changed, 55 insertions, 51 deletions
diff --git a/src/catch2/internal/catch_enum_values_registry.cpp b/src/catch2/internal/catch_enum_values_registry.cpp
index 0ab07b57..7e7deb87 100644
--- a/src/catch2/internal/catch_enum_values_registry.cpp
+++ b/src/catch2/internal/catch_enum_values_registry.cpp
@@ -51,8 +51,8 @@ namespace Catch {
return "{** unexpected enum value **}"_sr;
}
- std::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ) {
- auto enumInfo = std::make_unique<EnumInfo>();
+ Catch::Detail::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ) {
+ auto enumInfo = Catch::Detail::make_unique<EnumInfo>();
enumInfo->m_name = enumName;
enumInfo->m_values.reserve( values.size() );
diff --git a/src/catch2/internal/catch_enum_values_registry.hpp b/src/catch2/internal/catch_enum_values_registry.hpp
index 87494b07..080af01e 100644
--- a/src/catch2/internal/catch_enum_values_registry.hpp
+++ b/src/catch2/internal/catch_enum_values_registry.hpp
@@ -9,19 +9,19 @@
#define TWOBLUECUBES_CATCH_ENUMVALUESREGISTRY_H_INCLUDED
#include <catch2/interfaces/catch_interfaces_enum_values_registry.hpp>
+#include <catch2/internal/catch_unique_ptr.hpp>
#include <vector>
-#include <memory>
namespace Catch {
namespace Detail {
- std::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values );
+ Catch::Detail::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values );
class EnumValuesRegistry : public IMutableEnumValuesRegistry {
- std::vector<std::unique_ptr<EnumInfo>> m_enumInfos;
+ std::vector<Catch::Detail::unique_ptr<EnumInfo>> m_enumInfos;
EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values) override;
};
diff --git a/src/catch2/internal/catch_exception_translator_registry.cpp b/src/catch2/internal/catch_exception_translator_registry.cpp
index d99ec839..36640309 100644
--- a/src/catch2/internal/catch_exception_translator_registry.cpp
+++ b/src/catch2/internal/catch_exception_translator_registry.cpp
@@ -17,7 +17,7 @@ namespace Catch {
}
void ExceptionTranslatorRegistry::registerTranslator( const IExceptionTranslator* translator ) {
- m_translators.push_back( std::unique_ptr<const IExceptionTranslator>( translator ) );
+ m_translators.push_back( Detail::unique_ptr<const IExceptionTranslator>( translator ) );
}
#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
diff --git a/src/catch2/internal/catch_exception_translator_registry.hpp b/src/catch2/internal/catch_exception_translator_registry.hpp
index 48c385ab..7c170c08 100644
--- a/src/catch2/internal/catch_exception_translator_registry.hpp
+++ b/src/catch2/internal/catch_exception_translator_registry.hpp
@@ -11,7 +11,6 @@
#include <catch2/interfaces/catch_interfaces_exception.hpp>
#include <vector>
#include <string>
-#include <memory>
namespace Catch {
@@ -23,7 +22,7 @@ namespace Catch {
std::string tryTranslators() const;
private:
- std::vector<std::unique_ptr<IExceptionTranslator const>> m_translators;
+ ExceptionTranslators m_translators;
};
}
diff --git a/src/catch2/internal/catch_reporter_registry.cpp b/src/catch2/internal/catch_reporter_registry.cpp
index 9c37b7b2..4919e5df 100644
--- a/src/catch2/internal/catch_reporter_registry.cpp
+++ b/src/catch2/internal/catch_reporter_registry.cpp
@@ -21,14 +21,14 @@ namespace Catch {
ReporterRegistry::ReporterRegistry() {
// Because it is impossible to move out of initializer list,
// we have to add the elements manually
- m_factories["automake"] = std::make_unique<ReporterFactory<AutomakeReporter>>();
- m_factories["compact"] = std::make_unique<ReporterFactory<CompactReporter>>();
- m_factories["console"] = std::make_unique<ReporterFactory<ConsoleReporter>>();
- m_factories["junit"] = std::make_unique<ReporterFactory<JunitReporter>>();
- m_factories["sonarqube"] = std::make_unique<ReporterFactory<SonarQubeReporter>>();
- m_factories["tap"] = std::make_unique<ReporterFactory<TAPReporter>>();
- m_factories["teamcity"] = std::make_unique<ReporterFactory<TeamCityReporter>>();
- m_factories["xml"] = std::make_unique<ReporterFactory<XmlReporter>>();
+ m_factories["automake"] = Detail::make_unique<ReporterFactory<AutomakeReporter>>();
+ m_factories["compact"] = Detail::make_unique<ReporterFactory<CompactReporter>>();
+ m_factories["console"] = Detail::make_unique<ReporterFactory<ConsoleReporter>>();
+ m_factories["junit"] = Detail::make_unique<ReporterFactory<JunitReporter>>();
+ m_factories["sonarqube"] = Detail::make_unique<ReporterFactory<SonarQubeReporter>>();
+ m_factories["tap"] = Detail::make_unique<ReporterFactory<TAPReporter>>();
+ m_factories["teamcity"] = Detail::make_unique<ReporterFactory<TeamCityReporter>>();
+ m_factories["xml"] = Detail::make_unique<ReporterFactory<XmlReporter>>();
}
ReporterRegistry::~ReporterRegistry() = default;
diff --git a/src/catch2/internal/catch_stream.cpp b/src/catch2/internal/catch_stream.cpp
index 809acc0b..ec1179d3 100644
--- a/src/catch2/internal/catch_stream.cpp
+++ b/src/catch2/internal/catch_stream.cpp
@@ -13,19 +13,20 @@
#include <catch2/internal/catch_debug_console.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_singletons.hpp>
+#include <catch2/internal/catch_unique_ptr.hpp>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
-#include <memory>
namespace Catch {
Catch::IStream::~IStream() = default;
- namespace Detail { namespace {
+namespace Detail {
+ namespace {
template<typename WriterF, std::size_t bufferSize=256>
class StreamBufImpl : public std::streambuf {
char data[bufferSize];
@@ -104,11 +105,11 @@ namespace Catch {
///////////////////////////////////////////////////////////////////////////
class DebugOutStream : public IStream {
- std::unique_ptr<StreamBufImpl<OutputDebugWriter>> m_streamBuf;
+ Detail::unique_ptr<StreamBufImpl<OutputDebugWriter>> m_streamBuf;
mutable std::ostream m_os;
public:
DebugOutStream()
- : m_streamBuf( std::make_unique<StreamBufImpl<OutputDebugWriter>>() ),
+ : m_streamBuf( Detail::make_unique<StreamBufImpl<OutputDebugWriter>>() ),
m_os( m_streamBuf.get() )
{}
@@ -118,7 +119,8 @@ namespace Catch {
std::ostream& stream() const override { return m_os; }
};
- }} // namespace anon::detail
+ } // unnamed namespace
+} // namespace Detail
///////////////////////////////////////////////////////////////////////////
@@ -138,13 +140,13 @@ namespace Catch {
// This class encapsulates the idea of a pool of ostringstreams that can be reused.
struct StringStreams {
- std::vector<std::unique_ptr<std::ostringstream>> m_streams;
+ std::vector<Detail::unique_ptr<std::ostringstream>> m_streams;
std::vector<std::size_t> m_unused;
std::ostringstream m_referenceStream; // Used for copy state/ flags from
auto add() -> std::size_t {
if( m_unused.empty() ) {
- m_streams.push_back( std::unique_ptr<std::ostringstream>( new std::ostringstream ) );
+ m_streams.push_back( Detail::unique_ptr<std::ostringstream>( new std::ostringstream ) );
return m_streams.size()-1;
}
else {
diff --git a/src/catch2/internal/catch_template_test_registry.hpp b/src/catch2/internal/catch_template_test_registry.hpp
index 0873e884..b716c5f7 100644
--- a/src/catch2/internal/catch_template_test_registry.hpp
+++ b/src/catch2/internal/catch_template_test_registry.hpp
@@ -10,8 +10,6 @@
#include <catch2/internal/catch_preprocessor.hpp>
#include <catch2/internal/catch_meta.hpp>
-#include <memory>
-
// GCC 5 and older do not properly handle disabling unused-variable warning
// with a _Pragma. This means that we have to leak the suppression to the
// user code as well :-(
diff --git a/src/catch2/internal/catch_test_case_registry_impl.cpp b/src/catch2/internal/catch_test_case_registry_impl.cpp
index 7d16fb50..b7ebe977 100644
--- a/src/catch2/internal/catch_test_case_registry_impl.cpp
+++ b/src/catch2/internal/catch_test_case_registry_impl.cpp
@@ -116,14 +116,15 @@ namespace {
return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config );
}
- void TestRegistry::registerTest(std::unique_ptr<TestCaseInfo> testInfo, std::unique_ptr<ITestInvoker> testInvoker) {
+ void TestRegistry::registerTest(Detail::unique_ptr<TestCaseInfo> testInfo, Detail::unique_ptr<ITestInvoker> testInvoker) {
m_handles.emplace_back(testInfo.get(), testInvoker.get());
- m_infos.push_back(std::move(testInfo));
+ m_viewed_test_infos.push_back(testInfo.get());
+ m_owned_test_infos.push_back(std::move(testInfo));
m_invokers.push_back(std::move(testInvoker));
}
- std::vector<std::unique_ptr<TestCaseInfo>> const& TestRegistry::getAllInfos() const {
- return m_infos;
+ std::vector<TestCaseInfo*> const& TestRegistry::getAllInfos() const {
+ return m_viewed_test_infos;
}
std::vector<TestCaseHandle> const& TestRegistry::getAllTests() const {
diff --git a/src/catch2/internal/catch_test_case_registry_impl.hpp b/src/catch2/internal/catch_test_case_registry_impl.hpp
index 3d00896f..b7f49523 100644
--- a/src/catch2/internal/catch_test_case_registry_impl.hpp
+++ b/src/catch2/internal/catch_test_case_registry_impl.hpp
@@ -35,15 +35,19 @@ namespace Catch {
public:
~TestRegistry() override = default;
- virtual void registerTest( std::unique_ptr<TestCaseInfo> testInfo, std::unique_ptr<ITestInvoker> testInvoker );
+ virtual void registerTest( Detail::unique_ptr<TestCaseInfo> testInfo, Detail::unique_ptr<ITestInvoker> testInvoker );
- std::vector<std::unique_ptr<TestCaseInfo>> const& getAllInfos() const override;
+ std::vector<TestCaseInfo*> const& getAllInfos() const override;
std::vector<TestCaseHandle> const& getAllTests() const override;
std::vector<TestCaseHandle> const& getAllTestsSorted( IConfig const& config ) const override;
private:
- std::vector<std::unique_ptr<TestCaseInfo>> m_infos;
- std::vector<std::unique_ptr<ITestInvoker>> m_invokers;
+ std::vector<Detail::unique_ptr<TestCaseInfo>> m_owned_test_infos;
+ // Keeps a materialized vector for `getAllInfos`.
+ // We should get rid of that eventually (see interface note)
+ std::vector<TestCaseInfo*> m_viewed_test_infos;
+
+ std::vector<Detail::unique_ptr<ITestInvoker>> m_invokers;
std::vector<TestCaseHandle> m_handles;
mutable RunTests::InWhatOrder m_currentSortOrder = RunTests::InDeclarationOrder;
mutable std::vector<TestCaseHandle> m_sortedFunctions;
diff --git a/src/catch2/internal/catch_test_registry.cpp b/src/catch2/internal/catch_test_registry.cpp
index 070fde0d..583754e2 100644
--- a/src/catch2/internal/catch_test_registry.cpp
+++ b/src/catch2/internal/catch_test_registry.cpp
@@ -13,11 +13,11 @@
namespace Catch {
- std::unique_ptr<ITestInvoker> makeTestInvoker( void(*testAsFunction)() ) {
- return std::make_unique<TestInvokerAsFunction>( testAsFunction );
+ Detail::unique_ptr<ITestInvoker> makeTestInvoker( void(*testAsFunction)() ) {
+ return Detail::unique_ptr<ITestInvoker>( new TestInvokerAsFunction( testAsFunction ));
}
- AutoReg::AutoReg( std::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept {
+ AutoReg::AutoReg( Detail::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept {
CATCH_TRY {
getMutableRegistryHub()
.registerTest(
@@ -25,7 +25,8 @@ namespace Catch {
extractClassName( classOrMethod ),
nameAndTags,
lineInfo),
- std::move(invoker));
+ std::move(invoker)
+ );
} CATCH_CATCH_ALL {
// Do not throw when constructing global objects, instead register the exception to be processed later
getMutableRegistryHub().registerStartupException();
diff --git a/src/catch2/internal/catch_test_registry.hpp b/src/catch2/internal/catch_test_registry.hpp
index 8a027bd9..fd6d7d21 100644
--- a/src/catch2/internal/catch_test_registry.hpp
+++ b/src/catch2/internal/catch_test_registry.hpp
@@ -12,8 +12,7 @@
#include <catch2/interfaces/catch_interfaces_testcase.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_stringref.hpp>
-
-#include <memory>
+#include <catch2/internal/catch_unique_ptr.hpp>
// GCC 5 and older do not properly handle disabling unused-variable warning
// with a _Pragma. This means that we have to leak the suppression to the
@@ -38,11 +37,11 @@ public:
}
};
-std::unique_ptr<ITestInvoker> makeTestInvoker( void(*testAsFunction)() );
+Detail::unique_ptr<ITestInvoker> makeTestInvoker( void(*testAsFunction)() );
template<typename C>
-std::unique_ptr<ITestInvoker> makeTestInvoker( void (C::*testAsMethod)() ) {
- return std::make_unique<TestInvokerAsMethod<C>>( testAsMethod );
+Detail::unique_ptr<ITestInvoker> makeTestInvoker( void (C::*testAsMethod)() ) {
+ return Detail::unique_ptr<ITestInvoker>( new TestInvokerAsMethod<C>(testAsMethod) );
}
struct NameAndTags {
@@ -54,7 +53,7 @@ struct NameAndTags {
};
struct AutoReg : NonCopyable {
- AutoReg( std::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept;
+ AutoReg( Detail::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept;
};
} // end namespace Catch
diff --git a/src/catch2/internal/catch_test_spec_parser.cpp b/src/catch2/internal/catch_test_spec_parser.cpp
index db8812b9..d82cb5e0 100644
--- a/src/catch2/internal/catch_test_spec_parser.cpp
+++ b/src/catch2/internal/catch_test_spec_parser.cpp
@@ -199,9 +199,9 @@ namespace Catch {
if (!token.empty()) {
if (m_exclusion) {
- m_currentFilter.m_forbidden.emplace_back(std::make_unique<TestSpec::NamePattern>(token, m_substring));
+ m_currentFilter.m_forbidden.emplace_back(Detail::make_unique<TestSpec::NamePattern>(token, m_substring));
} else {
- m_currentFilter.m_required.emplace_back(std::make_unique<TestSpec::NamePattern>(token, m_substring));
+ m_currentFilter.m_required.emplace_back(Detail::make_unique<TestSpec::NamePattern>(token, m_substring));
}
}
m_substring.clear();
@@ -218,17 +218,17 @@ namespace Catch {
if (token.size() > 1 && token[0] == '.') {
token.erase(token.begin());
if (m_exclusion) {
- m_currentFilter.m_forbidden.emplace_back(std::make_unique<TestSpec::TagPattern>(".", m_substring));
- m_currentFilter.m_forbidden.emplace_back(std::make_unique<TestSpec::TagPattern>(token, m_substring));
+ m_currentFilter.m_forbidden.emplace_back(Detail::make_unique<TestSpec::TagPattern>(".", m_substring));
+ m_currentFilter.m_forbidden.emplace_back(Detail::make_unique<TestSpec::TagPattern>(token, m_substring));
} else {
- m_currentFilter.m_required.emplace_back(std::make_unique<TestSpec::TagPattern>(".", m_substring));
- m_currentFilter.m_required.emplace_back(std::make_unique<TestSpec::TagPattern>(token, m_substring));
+ m_currentFilter.m_required.emplace_back(Detail::make_unique<TestSpec::TagPattern>(".", m_substring));
+ m_currentFilter.m_required.emplace_back(Detail::make_unique<TestSpec::TagPattern>(token, m_substring));
}
}
if (m_exclusion) {
- m_currentFilter.m_forbidden.emplace_back(std::make_unique<TestSpec::TagPattern>(token, m_substring));
+ m_currentFilter.m_forbidden.emplace_back(Detail::make_unique<TestSpec::TagPattern>(token, m_substring));
} else {
- m_currentFilter.m_required.emplace_back(std::make_unique<TestSpec::TagPattern>(token, m_substring));
+ m_currentFilter.m_required.emplace_back(Detail::make_unique<TestSpec::TagPattern>(token, m_substring));
}
}
m_substring.clear();