From 874e878ba0e4e28a303789ffd5a7a858ee3e5c6b Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Mon, 28 Jul 2025 17:15:50 +0200 Subject: [PATCH] libutil: move LengthSink into sole user this should've been a filter from the start. since filter support in the old IO model is very bad we just move it into the only use of it instead Change-Id: Ifb9cfecf07587ae1d2d55072ddf505c86c79cc1b --- lix/libutil/references.cc | 23 ++++++++++++++++++----- lix/libutil/serialise.hh | 13 ------------- 2 files changed, 18 insertions(+), 18 deletions(-) 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. */