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ý
2020-05-31 15:20:24 +02:00
parent 41bbaa6d57
commit 1d1ccf8f3c
38 changed files with 141 additions and 125 deletions
+4 -4
View File
@@ -44,12 +44,12 @@ namespace Catch {
return createReporter(config->getReporterName(), config);
}
// On older platforms, returning std::unique_ptr<ListeningReporter>
// when the return type is std::unique_ptr<IStreamingReporter>
// On older platforms, returning unique_ptr<ListeningReporter>
// when the return type is unique_ptr<IStreamingReporter>
// doesn't compile without a std::move call. However, this causes
// a warning on newer platforms. Thus, we have to work around
// it a bit and downcast the pointer manually.
auto ret = std::unique_ptr<IStreamingReporter>(new ListeningReporter);
auto ret = Detail::unique_ptr<IStreamingReporter>(new ListeningReporter);
auto& multi = static_cast<ListeningReporter&>(*ret);
auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners();
for (auto const& listener : listeners) {
@@ -252,7 +252,7 @@ namespace Catch {
}
Config& Session::config() {
if( !m_config )
m_config = std::make_unique<Config>( m_configData );
m_config = Detail::make_unique<Config>( m_configData );
return *m_config;
}