diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2020-07-15 23:19:41 +0000 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2020-07-15 23:37:49 +0000 |
commit | 5602637d9ea195784368e99a226718fc95e6b978 (patch) | |
tree | 176c4f8fa83699dc73784239a973c7bd2baae3e7 | |
parent | bc109648c41f8021707b55b815e68a890a09f2f6 (diff) |
Revert "LocalStore::addToStoreFromDump copy in chunks"
This reverts commit 592851fb67cd15807109d6f65fb81f6af89af966. We don't
need this extra feature anymore
-rw-r--r-- | src/libstore/local-store.cc | 2 | ||||
-rw-r--r-- | src/libutil/serialise.cc | 33 | ||||
-rw-r--r-- | src/libutil/serialise.hh | 11 |
3 files changed, 15 insertions, 31 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 07e1679da..b2b5afadd 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1037,7 +1037,7 @@ StorePath LocalStore::addToStore(const string & name, const Path & _srcPath, FileIngestionMethod method, HashType hashAlgo, PathFilter & filter, RepairFlag repair) { Path srcPath(absPath(_srcPath)); - auto source = sinkToSource([&](Sink & sink, size_t & wanted) { + auto source = sinkToSource([&](Sink & sink) { if (method == FileIngestionMethod::Recursive) dumpPath(srcPath, sink, filter); else diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc index 4c72dc9f2..00c945113 100644 --- a/src/libutil/serialise.cc +++ b/src/libutil/serialise.cc @@ -165,43 +165,35 @@ size_t StringSource::read(unsigned char * data, size_t len) #endif std::unique_ptr<Source> sinkToSource( - std::function<void(Sink &, size_t &)> fun, + std::function<void(Sink &)> fun, std::function<void()> eof) { struct SinkToSource : Source { - typedef boost::coroutines2::coroutine<std::basic_string<uint8_t>> coro_t; + typedef boost::coroutines2::coroutine<std::string> coro_t; - std::function<void(Sink &, size_t &)> fun; + std::function<void(Sink &)> fun; std::function<void()> eof; std::optional<coro_t::pull_type> coro; bool started = false; - /* It would be nicer to have the co-routines have both args and a - return value, but unfortunately that was removed from Boost's - implementation for some reason, so we use some extra state instead. - */ - size_t wanted = 0; - - SinkToSource(std::function<void(Sink &, size_t &)> fun, std::function<void()> eof) + SinkToSource(std::function<void(Sink &)> fun, std::function<void()> eof) : fun(fun), eof(eof) { } - std::basic_string<uint8_t> cur; + std::string cur; size_t pos = 0; size_t read(unsigned char * data, size_t len) override { - wanted = len < cur.size() ? 0 : len - cur.size(); - if (!coro) { + if (!coro) coro = coro_t::pull_type([&](coro_t::push_type & yield) { - LambdaSink sink([&](const uint8_t * data, size_t len) { - if (len) yield(std::basic_string<uint8_t> { data, len }); + LambdaSink sink([&](const unsigned char * data, size_t len) { + if (len) yield(std::string((const char *) data, len)); }); - fun(sink, wanted); + fun(sink); }); - } if (!*coro) { eof(); abort(); } @@ -211,10 +203,11 @@ std::unique_ptr<Source> sinkToSource( pos = 0; } - auto numCopied = cur.copy(data, len, pos); - pos += numCopied; + auto n = std::min(cur.size() - pos, len); + memcpy(data, (unsigned char *) cur.data() + pos, n); + pos += n; - return numCopied; + return n; } }; diff --git a/src/libutil/serialise.hh b/src/libutil/serialise.hh index 3e3735ca5..aa6b42597 100644 --- a/src/libutil/serialise.hh +++ b/src/libutil/serialise.hh @@ -273,19 +273,10 @@ struct ChainSource : Source /* Convert a function that feeds data into a Sink into a Source. The Source executes the function as a coroutine. */ std::unique_ptr<Source> sinkToSource( - std::function<void(Sink &, size_t &)> fun, - std::function<void()> eof = []() { - throw EndOfFile("coroutine has finished"); - }); - -static inline std::unique_ptr<Source> sinkToSource( std::function<void(Sink &)> fun, std::function<void()> eof = []() { throw EndOfFile("coroutine has finished"); - }) -{ - return sinkToSource([fun](Sink & s, size_t & _) { fun(s); }, eof); -} + }); void writePadding(size_t len, Sink & sink); |