diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-03-01 14:54:11 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-03-01 14:54:11 +0100 |
commit | 374908726b87f6cd137ea7d097fdcda57003594e (patch) | |
tree | ced2c4fac0c4166d986c7fbc977b7798371095e8 /src/libutil/serialise.cc | |
parent | 07a0b8ca671669794f51f9d886397bf038a8881e (diff) |
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...)
Diffstat (limited to 'src/libutil/serialise.cc')
-rw-r--r-- | src/libutil/serialise.cc | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc index 6064e15f5..950e6362a 100644 --- a/src/libutil/serialise.cc +++ b/src/libutil/serialise.cc @@ -207,10 +207,10 @@ size_t readString(unsigned char * buf, size_t max, Source & source) string readString(Source & source) { auto len = readNum<size_t>(source); - auto buf = std::make_unique<unsigned char[]>(len); - source(buf.get(), len); + std::string res(len, 0); + source((unsigned char*) res.data(), len); readPadding(len, source); - return string((char *) buf.get(), len); + return res; } Source & operator >> (Source & in, string & s) |