about summary refs log tree commit diff
path: root/src/libutil/util.hh
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2016-11-16T15·21+0100
committerEelco Dolstra <edolstra@gmail.com>2016-11-16T15·21+0100
commit4be4f6de56f4de77f6a376f1a40ed75eb641bb89 (patch)
treedbaa5c53f816f85cde44e0c89661b67a6a0a4b92 /src/libutil/util.hh
parent10ae8fabf1e7e7bd8817b93560df7484c3bd18b8 (diff)
S3BinaryCacheStore:: Eliminate a string copy while uploading
This cuts hydra-queue-runner's peak memory usage by about a third.
Diffstat (limited to 'src/libutil/util.hh')
-rw-r--r--src/libutil/util.hh14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 50b96f7ed92c..a8f6f99b957f 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -431,4 +431,18 @@ void callSuccess(
 }
 
 
+/* A variant of std::istringstream that doesn't its string
+   argument. This is useful for large strings. The caller must ensure
+   that the string object is not destroyed while it's referenced by
+   this object. */
+struct istringstream_nocopy : public std::stringstream
+{
+    istringstream_nocopy(const std::string & s)
+    {
+        rdbuf()->pubsetbuf(
+            (char *) s.data(), s.size());
+    }
+};
+
+
 }