From b5aa3a41970e78fc646de3ff943377f436ac9bf6 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sat, 1 Mar 2025 23:55:42 +0100 Subject: [PATCH] libutil: inline ChainSource into sole remaining user Change-Id: If0c81472a2e9b70e695631c147ce7eaae28d69d6 --- lix/libstore/local-store.cc | 21 +++++++++++++++++++++ lix/libutil/serialise.cc | 14 -------------- lix/libutil/serialise.hh | 15 --------------- 3 files changed, 21 insertions(+), 29 deletions(-) diff --git a/lix/libstore/local-store.cc b/lix/libstore/local-store.cc index 9ea377dd0..10b66a475 100644 --- a/lix/libstore/local-store.cc +++ b/lix/libstore/local-store.cc @@ -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 }; diff --git a/lix/libutil/serialise.cc b/lix/libutil/serialise.cc index a8b10a590..ba7dbffc7 100644 --- a/lix/libutil/serialise.cc +++ b/lix/libutil/serialise.cc @@ -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); - } - } -} - } diff --git a/lix/libutil/serialise.hh b/lix/libutil/serialise.hh index 3e5f391cd..69230f6a2 100644 --- a/lix/libutil/serialise.hh +++ b/lix/libutil/serialise.hh @@ -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 && g) : g(std::move(g)) {}