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:
parent
cda3ef96a2
commit
c8216caa6c
1 changed files with 9 additions and 0 deletions
|
@ -43,6 +43,11 @@ namespace Loki
|
||||||
|
|
||||||
void write(std::string& s, const char* from, const char* to) {
|
void write(std::string& s, const char* from, const char* to) {
|
||||||
assert(from <= 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);
|
s.append(from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,10 +90,14 @@ namespace Loki
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintfState<std::string&, char> SPrintf(std::string& s, const char* format) {
|
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);
|
return PrintfState<std::string&, char>(s, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintfState<std::string&, char> SPrintf(std::string& s, const std::string& 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());
|
return PrintfState<std::string&, char>(s, format.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue