forked from lix-project/lix
Separate concerns in scanForReferences
with TeeSink
This also will make it easier to use a `HashModuloSink` instead for CA derivations.
This commit is contained in:
parent
090960b725
commit
c56356bacc
1 changed files with 7 additions and 8 deletions
|
@ -48,13 +48,12 @@ static void search(const unsigned char * s, size_t len,
|
||||||
|
|
||||||
struct RefScanSink : Sink
|
struct RefScanSink : Sink
|
||||||
{
|
{
|
||||||
HashSink hashSink;
|
|
||||||
StringSet hashes;
|
StringSet hashes;
|
||||||
StringSet seen;
|
StringSet seen;
|
||||||
|
|
||||||
string tail;
|
string tail;
|
||||||
|
|
||||||
RefScanSink() : hashSink(htSHA256) { }
|
RefScanSink() { }
|
||||||
|
|
||||||
void operator () (const unsigned char * data, size_t len);
|
void operator () (const unsigned char * data, size_t len);
|
||||||
};
|
};
|
||||||
|
@ -62,8 +61,6 @@ struct RefScanSink : Sink
|
||||||
|
|
||||||
void RefScanSink::operator () (const unsigned char * data, size_t len)
|
void RefScanSink::operator () (const unsigned char * data, size_t len)
|
||||||
{
|
{
|
||||||
hashSink(data, len);
|
|
||||||
|
|
||||||
/* It's possible that a reference spans the previous and current
|
/* It's possible that a reference spans the previous and current
|
||||||
fragment, so search in the concatenation of the tail of the
|
fragment, so search in the concatenation of the tail of the
|
||||||
previous fragment and the start of the current fragment. */
|
previous fragment and the start of the current fragment. */
|
||||||
|
@ -82,7 +79,9 @@ void RefScanSink::operator () (const unsigned char * data, size_t len)
|
||||||
PathSet scanForReferences(const string & path,
|
PathSet scanForReferences(const string & path,
|
||||||
const PathSet & refs, HashResult & hash)
|
const PathSet & refs, HashResult & hash)
|
||||||
{
|
{
|
||||||
RefScanSink sink;
|
RefScanSink refsSink;
|
||||||
|
HashSink hashSink { htSHA256 };
|
||||||
|
TeeSink sink { refsSink, hashSink };
|
||||||
std::map<string, Path> backMap;
|
std::map<string, Path> backMap;
|
||||||
|
|
||||||
/* For efficiency (and a higher hit rate), just search for the
|
/* For efficiency (and a higher hit rate), just search for the
|
||||||
|
@ -97,7 +96,7 @@ PathSet scanForReferences(const string & path,
|
||||||
assert(s.size() == refLength);
|
assert(s.size() == refLength);
|
||||||
assert(backMap.find(s) == backMap.end());
|
assert(backMap.find(s) == backMap.end());
|
||||||
// parseHash(htSHA256, s);
|
// parseHash(htSHA256, s);
|
||||||
sink.hashes.insert(s);
|
refsSink.hashes.insert(s);
|
||||||
backMap[s] = i;
|
backMap[s] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,13 +105,13 @@ PathSet scanForReferences(const string & path,
|
||||||
|
|
||||||
/* Map the hashes found back to their store paths. */
|
/* Map the hashes found back to their store paths. */
|
||||||
PathSet found;
|
PathSet found;
|
||||||
for (auto & i : sink.seen) {
|
for (auto & i : refsSink.seen) {
|
||||||
std::map<string, Path>::iterator j;
|
std::map<string, Path>::iterator j;
|
||||||
if ((j = backMap.find(i)) == backMap.end()) abort();
|
if ((j = backMap.find(i)) == backMap.end()) abort();
|
||||||
found.insert(j->second);
|
found.insert(j->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
hash = sink.hashSink.finish();
|
hash = hashSink.finish();
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue