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
This commit is contained in:
rich_sposato 2011-10-04 20:48:36 +00:00
parent cda3ef96a2
commit c8216caa6c

View file

@ -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<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());
}