diff --git a/src/SafeFormat.cpp b/src/SafeFormat.cpp index ad6ce2c..582ebfd 100644 --- a/src/SafeFormat.cpp +++ b/src/SafeFormat.cpp @@ -43,6 +43,11 @@ namespace Loki void write(std::string& s, const char* from, const char* to) { assert(from <= to); + const size_t addCount = to - from; + if ( s.capacity() <= s.size() + addCount ) + { + s.reserve( 2 * s.size() + addCount ); + } s.append(from, to); } @@ -85,10 +90,14 @@ namespace Loki } PrintfState SPrintf(std::string& s, const char* format) { + const size_t estimate = ::strlen( format ) + 128; + s.reserve( estimate ); return PrintfState(s, format); } PrintfState SPrintf(std::string& s, const std::string& format) { + const size_t estimate = format.size() + 128; + s.reserve( estimate ); return PrintfState(s, format.c_str()); }