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.
This commit is contained in:
Martin Hořeňovský committed 2020-05-31 15:20:24 +02:00
1 parent 41bbaa6d57
commit 1d1ccf8f3c
38 files changed
+141 -125

No files matched your search

@@ -10,6 +10,7 @@
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <string>
#include <vector>
@@ -18,7 +19,7 @@ namespace Catch {
using exceptionTranslateFunction = std::string(*)();
struct IExceptionTranslator;
using ExceptionTranslators = std::vector<std::unique_ptr<IExceptionTranslator const>>;
using ExceptionTranslators = std::vector<Detail::unique_ptr<IExceptionTranslator const>>;
struct IExceptionTranslator {
virtual ~IExceptionTranslator();
@@ -8,7 +8,7 @@
#ifndef TWOBLUECUBES_CATCH_INTERFACES_GENERATORTRACKER_INCLUDED
#define TWOBLUECUBES_CATCH_INTERFACES_GENERATORTRACKER_INCLUDED
#include <memory>
#include <catch2/internal/catch_unique_ptr.hpp>
namespace Catch {
@@ -29,7 +29,7 @@ namespace Catch {
// can be retrieved).
virtual bool next() = 0;
};
using GeneratorBasePtr = std::unique_ptr<GeneratorUntypedBase>;
using GeneratorBasePtr = Catch::Detail::unique_ptr<GeneratorUntypedBase>;
} // namespace Generators
@@ -9,9 +9,9 @@
#define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
#include <catch2/internal/catch_common.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <string>
#include <memory>
namespace Catch {
@@ -28,7 +28,7 @@ namespace Catch {
class StartupExceptionRegistry;
using IReporterFactoryPtr = std::unique_ptr<IReporterFactory>;
using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
struct IRegistryHub {
virtual ~IRegistryHub();
@@ -46,7 +46,7 @@ namespace Catch {
virtual ~IMutableRegistryHub();
virtual void registerReporter( std::string const& name, IReporterFactoryPtr factory ) = 0;
virtual void registerListener( IReporterFactoryPtr factory ) = 0;
virtual void registerTest(std::unique_ptr<TestCaseInfo>&& testInfo, std::unique_ptr<ITestInvoker>&& invoker) = 0;
virtual void registerTest(Detail::unique_ptr<TestCaseInfo>&& testInfo, Detail::unique_ptr<ITestInvoker>&& invoker) = 0;
virtual void registerTranslator( const IExceptionTranslator* translator ) = 0;
virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
virtual void registerStartupException() noexcept = 0;
@@ -17,6 +17,7 @@
#include <catch2/internal/catch_message_info.hpp>
#include <catch2/internal/catch_option.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <catch2/benchmark/catch_estimate.hpp>
#include <catch2/benchmark/catch_outlier_classification.hpp>
@@ -25,7 +26,6 @@
#include <string>
#include <iosfwd>
#include <map>
#include <memory>
#include <algorithm>
namespace Catch {
@@ -222,14 +222,14 @@ namespace Catch {
virtual void listTags(std::vector<TagInfo> const& tags, Config const& config);
};
using IStreamingReporterPtr = std::unique_ptr<IStreamingReporter>;
using IStreamingReporterPtr = Detail::unique_ptr<IStreamingReporter>;
struct IReporterFactory {
virtual ~IReporterFactory();
virtual IStreamingReporterPtr create( ReporterConfig const& config ) const = 0;
virtual std::string getDescription() const = 0;
};
using IReporterFactoryPtr = std::unique_ptr<IReporterFactory>;
using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
struct IReporterRegistry {
using FactoryMap = std::map<std::string, IReporterFactoryPtr>;
@@ -9,7 +9,6 @@
#define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
#include <vector>
#include <memory>
namespace Catch {
@@ -26,7 +25,8 @@ namespace Catch {
struct ITestCaseRegistry {
virtual ~ITestCaseRegistry();
virtual std::vector<std::unique_ptr<TestCaseInfo>> const& getAllInfos() const = 0;
// TODO: this exists only for adding filenames to test cases -- let's expose this in a saner way later
virtual std::vector<TestCaseInfo* > const& getAllInfos() const = 0;
virtual std::vector<TestCaseHandle> const& getAllTests() const = 0;
virtual std::vector<TestCaseHandle> const& getAllTestsSorted( IConfig const& config ) const = 0;
};