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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user