From 42bc395b63260e13f42e4bf348823799e78e445f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 4 Mar 2016 16:49:56 +0100 Subject: Eliminate some large string copying --- src/libutil/serialise.cc | 4 ++-- src/libutil/serialise.hh | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src/libutil') diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc index a3cd4ff0d02c..5c45c890f7b6 100644 --- a/src/libutil/serialise.cc +++ b/src/libutil/serialise.cc @@ -288,11 +288,11 @@ template PathSet readStrings(Source & source); void StringSink::operator () (const unsigned char * data, size_t len) { static bool warned = false; - if (!warned && s.size() > threshold) { + if (!warned && s->size() > threshold) { warnLargeDump(); warned = true; } - s.append((const char *) data, len); + s->append((const char *) data, len); } diff --git a/src/libutil/serialise.hh b/src/libutil/serialise.hh index 0fdc4037b2d7..9ba6391f817a 100644 --- a/src/libutil/serialise.hh +++ b/src/libutil/serialise.hh @@ -110,7 +110,9 @@ private: /* A sink that writes data to a string. */ struct StringSink : Sink { - string s; + ref s; + StringSink() : s(make_ref()) { }; + StringSink(ref s) : s(s) { }; void operator () (const unsigned char * data, size_t len) override; }; -- cgit 1.4.1