diff --git a/lix/libutil/references.cc b/lix/libutil/references.cc index 61122d370..1b9a2a955 100644 --- a/lix/libutil/references.cc +++ b/lix/libutil/references.cc @@ -155,12 +155,25 @@ size_t RewritingSource::read(char * data, size_t len) HashResult computeHashModulo(HashType ht, const std::string & modulus, Source & source) { - HashSink hashSink(ht); - LengthSink lengthSink; - RewritingSource rewritingSource(modulus, std::string(modulus.size(), 0), source); + struct LengthSink : Sink + { + Sink & inner; + uint64_t length = 0; - TeeSink tee{hashSink, lengthSink}; - rewritingSource.drainInto(tee); + LengthSink(Sink & inner) : inner(inner) {} + + void operator()(std::string_view data) override + { + length += data.size(); + inner(data); + } + }; + + HashSink hashSink(ht); + RewritingSource rewritingSource(modulus, std::string(modulus.size(), 0), source); + LengthSink lengthSink{hashSink}; + + rewritingSource.drainInto(lengthSink); /* Hash the positions of the self-references. This ensures that a NAR with self-references and a NAR with some of the diff --git a/lix/libutil/serialise.hh b/lix/libutil/serialise.hh index 2ea65f3a7..aaf37fb3b 100644 --- a/lix/libutil/serialise.hh +++ b/lix/libutil/serialise.hh @@ -226,19 +226,6 @@ struct TeeSource : Source } }; -/** - * A sink that that just counts the number of bytes given to it - */ -struct LengthSink : Sink -{ - uint64_t length = 0; - - void operator () (std::string_view data) override - { - length += data.size(); - } -}; - /** * Convert a function into a sink. */