mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-04 05:09:53 +01:00
Clean-up re-usable string streams
This commit is contained in:
parent
f417995afc
commit
091595780e
@ -87,6 +87,7 @@ namespace Catch {
|
|||||||
delete getTheRegistryHub();
|
delete getTheRegistryHub();
|
||||||
getTheRegistryHub() = nullptr;
|
getTheRegistryHub() = nullptr;
|
||||||
cleanUpContext();
|
cleanUpContext();
|
||||||
|
ReusableStringStream::cleanup();
|
||||||
}
|
}
|
||||||
std::string translateActiveException() {
|
std::string translateActiveException() {
|
||||||
return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
|
return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
|
||||||
|
@ -145,6 +145,7 @@ namespace Catch {
|
|||||||
std::vector<std::unique_ptr<std::ostringstream>> m_streams;
|
std::vector<std::unique_ptr<std::ostringstream>> m_streams;
|
||||||
std::vector<std::size_t> m_unused;
|
std::vector<std::size_t> m_unused;
|
||||||
std::ostringstream m_referenceStream; // Used for copy state/ flags from
|
std::ostringstream m_referenceStream; // Used for copy state/ flags from
|
||||||
|
static StringStreams* s_instance;
|
||||||
|
|
||||||
auto add() -> std::size_t {
|
auto add() -> std::size_t {
|
||||||
if( m_unused.empty() ) {
|
if( m_unused.empty() ) {
|
||||||
@ -165,11 +166,21 @@ namespace Catch {
|
|||||||
|
|
||||||
// !TBD: put in TLS
|
// !TBD: put in TLS
|
||||||
static auto instance() -> StringStreams& {
|
static auto instance() -> StringStreams& {
|
||||||
static StringStreams s_stringStreams;
|
if( !s_instance )
|
||||||
return s_stringStreams;
|
s_instance = new StringStreams();
|
||||||
|
return *s_instance;
|
||||||
|
}
|
||||||
|
static void cleanup() {
|
||||||
|
delete s_instance;
|
||||||
|
s_instance = nullptr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
StringStreams* StringStreams::s_instance = nullptr;
|
||||||
|
|
||||||
|
void ReusableStringStream::cleanup() {
|
||||||
|
StringStreams::cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
ReusableStringStream::ReusableStringStream()
|
ReusableStringStream::ReusableStringStream()
|
||||||
: m_index( StringStreams::instance().add() ),
|
: m_index( StringStreams::instance().add() ),
|
||||||
|
@ -43,6 +43,8 @@ namespace Catch {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
auto get() -> std::ostream& { return *m_oss; }
|
auto get() -> std::ostream& { return *m_oss; }
|
||||||
|
|
||||||
|
static void cleanup();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user