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

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2/internal/catch_stream.cpp
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/catch_stream.cpp
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/catch_stream.cpp')
-rw-r--r--src/catch2/internal/catch_stream.cpp16
1 files changed, 9 insertions, 7 deletions
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 {