libutil: inline ChainSource into sole remaining user

Change-Id: If0c81472a2e9b70e695631c147ce7eaae28d69d6
This commit is contained in:
eldritch horrors
2025-03-02 17:37:12 +00:00
parent 820c9bdaf5
commit b5aa3a4197
3 changed files with 21 additions and 29 deletions
+21
View File
@@ -1346,6 +1346,27 @@ try {
AutoCloseFD tempDirFd;
if (!inMemory) {
struct ChainSource : Source
{
Source & source1, & source2;
bool useSecond = false;
ChainSource(Source & s1, Source & s2) : source1(s1), source2(s2) {}
size_t read(char * data, size_t len) override
{
if (useSecond) {
return source2.read(data, len);
} else {
try {
return source1.read(data, len);
} catch (EndOfFile &) {
useSecond = true;
return this->read(data, len);
}
}
}
};
/* Drain what we pulled so far, and then keep on pulling */
StringSource dumpSource { dump };
ChainSource bothSource { dumpSource, source };
-14
View File
@@ -321,18 +321,4 @@ void StringSink::operator () (std::string_view data)
s.append(data);
}
size_t ChainSource::read(char * data, size_t len)
{
if (useSecond) {
return source2.read(data, len);
} else {
try {
return source1.read(data, len);
} catch (EndOfFile &) {
useSecond = true;
return this->read(data, len);
}
}
}
}
-15
View File
@@ -324,21 +324,6 @@ struct LambdaSource : Source
}
};
/**
* Chain two sources together so after the first is exhausted, the second is
* used
*/
struct ChainSource : Source
{
Source & source1, & source2;
bool useSecond = false;
ChainSource(Source & s1, Source & s2)
: source1(s1), source2(s2)
{ }
size_t read(char * data, size_t len) override;
};
struct GeneratorSource : Source
{
GeneratorSource(Generator<Bytes> && g) : g(std::move(g)) {}