From: <ric...@us...> - 2011-10-04 20:48:42
|
Revision: 1137 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1137&view=rev Author: rich_sposato Date: 2011-10-04 20:48:36 +0000 (Tue, 04 Oct 2011) Log Message: ----------- Fix for bug 2694073. Added calls to reserve so append won't resize as often. Modified Paths: -------------- trunk/src/SafeFormat.cpp Modified: trunk/src/SafeFormat.cpp =================================================================== --- trunk/src/SafeFormat.cpp 2011-10-04 00:52:09 UTC (rev 1136) +++ trunk/src/SafeFormat.cpp 2011-10-04 20:48:36 UTC (rev 1137) @@ -43,6 +43,11 @@ 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 @@ } PrintfState<std::string&, char> SPrintf(std::string& s, const char* format) { + const size_t estimate = ::strlen( format ) + 128; + s.reserve( estimate ); return PrintfState<std::string&, char>(s, format); } PrintfState<std::string&, char> SPrintf(std::string& s, const std::string& format) { + const size_t estimate = format.size() + 128; + s.reserve( estimate ); return PrintfState<std::string&, char>(s, format.c_str()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |