Introduced ReusableStringStream and removed all uses of std::ostringstream from the main path

ReusableStringStream holds a std::ostringstream internally, but only exposes the ostream interface.
It caches a pool of ostringstreams in a vector which is currently global, but will be made thread-local.

Altogether this should enable both runtime and compile-time benefits. although more work is needed to realise the compile time opportunities.
This commit is contained in:
Phil Nash
2017-11-07 18:01:10 +00:00
parent 868e125d49
commit 56e1075613
26 changed files with 202 additions and 114 deletions

View File

@@ -14,7 +14,7 @@
#include "../internal/catch_timer.h"
#include <assert.h>
#include <sstream>
#include <ctime>
#include <algorithm>
@@ -230,15 +230,15 @@ namespace Catch {
xml.writeAttribute( "message", result.getExpandedExpression() );
xml.writeAttribute( "type", result.getTestMacroName() );
std::ostringstream oss;
ReusableStringStream rss;
if( !result.getMessage().empty() )
oss << result.getMessage() << '\n';
rss << result.getMessage() << '\n';
for( auto const& msg : stats.infoMessages )
if( msg.type == ResultWas::Info )
oss << msg.message << '\n';
rss << msg.message << '\n';
oss << "at " << result.getSourceInfo();
xml.writeText( oss.str(), false );
rss << "at " << result.getSourceInfo();
xml.writeText( rss.str(), false );
}
}