From 15f6957e389bb72ad9543ab8ef4df0a211d35542 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 7 May 2022 13:28:52 +0100 Subject: Simplify blockSize iteration --- netfs/fuse/fuseFiles.cpp | 56 ++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp index 9baf51f..c1709cd 100644 --- a/netfs/fuse/fuseFiles.cpp +++ b/netfs/fuse/fuseFiles.cpp @@ -151,6 +151,18 @@ namespace NetFS { } } + template + void + blockSizeIterate(FuseApp::OpenFile::BlockSizes bs, CB && cb) + { + if (bs.size1) { + cb(bs.size1); + } + while (bs.N--) { + cb(bs.sizeN); + } + } + int FuseApp::read(const char *, char * buf, size_t s, off_t o, struct fuse_file_info * fi) { @@ -184,7 +196,7 @@ namespace NetFS { auto remote = of->remote; auto bytes = reinterpret_cast(buf); if (fcr->Async) { - auto sendSome = [&bytes, &o, &remote, &of](safe blockSize) { + blockSizeIterate(of->blockSizes(s), [&bytes, &o, &remote, &of](safe blockSize) { waitOnWriteRangeAndThen( blockSize, o, of, [o, blockSize, bytes, &of, remote](const auto & key) { auto p = std::make_shared(); @@ -203,37 +215,21 @@ namespace NetFS { }); bytes += blockSize; o += blockSize; - }; - auto bs = of->blockSizes(s); - if (bs.size1) { - sendSome(bs.size1); - } - while (bs.N--) { - sendSome(bs.sizeN); - } + }); + } + else if (of->bodyMaxSize < s) { + std::vector> ops; + blockSizeIterate(of->blockSizes(s), [&ops, &bytes, &o, &remote](safe blockSize) { + ops.emplace_back(remote->writeAsync(o, blockSize, std::make_pair(bytes, bytes + blockSize))); + bytes += blockSize; + o += blockSize; + }); + std::for_each(ops.begin(), ops.end(), [](auto && op) { + op.get(); + }); } else { - if (of->bodyMaxSize < s) { - std::vector> ops; - auto sendSome = [&ops, &bytes, &o, &remote](safe blockSize) { - ops.emplace_back(remote->writeAsync(o, blockSize, std::make_pair(bytes, bytes + blockSize))); - bytes += blockSize; - o += blockSize; - }; - auto bs = of->blockSizes(s); - if (bs.size1) { - sendSome(bs.size1); - } - while (bs.N--) { - sendSome(bs.sizeN); - } - std::for_each(ops.begin(), ops.end(), [](auto && op) { - op.get(); - }); - } - else { - remote->write(o, safe {s}, std::make_pair(bytes, bytes + s)); - } + remote->write(o, safe {s}, std::make_pair(bytes, bytes + s)); } return safe {s}; } -- cgit v1.2.3