From c8216caa6c1364a8b64294dad7f3036657432130 Mon Sep 17 00:00:00 2001 From: rich_sposato Date: Tue, 4 Oct 2011 20:48:36 +0000 Subject: [PATCH] Fix for bug 2694073. Added calls to reserve so append won't resize as often. git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@1137 7ec92016-0320-0410-acc4-a06ded1c099a --- src/SafeFormat.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) 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()); }