From 374908726b87f6cd137ea7d097fdcda57003594e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 1 Mar 2017 14:54:11 +0100 Subject: [PATCH] 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...) --- src/libutil/serialise.cc | 6 +++--- 1 file 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(source); - auto buf = std::make_unique(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)