From 4be4f6de56f4de77f6a376f1a40ed75eb641bb89 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 16 Nov 2016 16:21:30 +0100 Subject: S3BinaryCacheStore:: Eliminate a string copy while uploading This cuts hydra-queue-runner's peak memory usage by about a third. --- src/libutil/hash.cc | 2 +- src/libutil/util.hh | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src/libutil') diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc index 81aced0fde16..49e781980f3a 100644 --- a/src/libutil/hash.cc +++ b/src/libutil/hash.cc @@ -106,7 +106,7 @@ Hash parseHash(HashType ht, const string & s) string s2(s, i * 2, 2); if (!isxdigit(s2[0]) || !isxdigit(s2[1])) throw BadHash(format("invalid hash ‘%1%’") % s); - std::istringstream str(s2); + istringstream_nocopy str(s2); int n; str >> std::hex >> n; hash.hash[i] = n; 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()); + } +}; + + } -- cgit 1.4.1