readString(): Read directly into std::string
When reading a huge string, this halves memory consumption. (Strictly speaking, this appears only valid in C++17, but who cares...)
This commit is contained in:
parent
07a0b8ca67
commit
374908726b
1 changed files with 3 additions and 3 deletions
|
@ -207,10 +207,10 @@ size_t readString(unsigned char * buf, size_t max, Source & source)
|
||||||
string readString(Source & source)
|
string readString(Source & source)
|
||||||
{
|
{
|
||||||
auto len = readNum<size_t>(source);
|
auto len = readNum<size_t>(source);
|
||||||
auto buf = std::make_unique<unsigned char[]>(len);
|
std::string res(len, 0);
|
||||||
source(buf.get(), len);
|
source((unsigned char*) res.data(), len);
|
||||||
readPadding(len, source);
|
readPadding(len, source);
|
||||||
return string((char *) buf.get(), len);
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
Source & operator >> (Source & in, string & s)
|
Source & operator >> (Source & in, string & s)
|
||||||
|
|
Loading…
Reference in a new issue