
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.
35 lines
1.4 KiB
C++
35 lines
1.4 KiB
C++
/*
|
|
* Created by Martin on 25/07/2017.
|
|
*
|
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
*/
|
|
|
|
#include <catch2/internal/catch_test_registry.hpp>
|
|
#include <catch2/internal/catch_compiler_capabilities.hpp>
|
|
#include <catch2/catch_test_case_info.hpp>
|
|
#include <catch2/internal/catch_test_case_registry_impl.hpp>
|
|
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
|
|
|
|
namespace Catch {
|
|
|
|
Detail::unique_ptr<ITestInvoker> makeTestInvoker( void(*testAsFunction)() ) {
|
|
return Detail::unique_ptr<ITestInvoker>( new TestInvokerAsFunction( testAsFunction ));
|
|
}
|
|
|
|
AutoReg::AutoReg( Detail::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept {
|
|
CATCH_TRY {
|
|
getMutableRegistryHub()
|
|
.registerTest(
|
|
makeTestCaseInfo(
|
|
extractClassName( classOrMethod ),
|
|
nameAndTags,
|
|
lineInfo),
|
|
std::move(invoker)
|
|
);
|
|
} CATCH_CATCH_ALL {
|
|
// Do not throw when constructing global objects, instead register the exception to be processed later
|
|
getMutableRegistryHub().registerStartupException();
|
|
}
|
|
}
|
|
}
|