From 06a30ec8df139cd4c7fb21ba9beb1dc54a4fc3fa Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 6 Oct 2024 19:43:34 +0200 Subject: [PATCH] hydra-queue-runner/nar-extractor: address review comments * Turn `NarMemberData` in `MyFileHandle` into a reference. * `expectedSize` now uses an initializer. * Used `std::make_unique` instead of `std::unique_ptr(new ...)` as suggested by clangd. --- src/hydra-queue-runner/nar-extractor.cc | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/hydra-queue-runner/nar-extractor.cc b/src/hydra-queue-runner/nar-extractor.cc index 31c0db65..7619b2ee 100644 --- a/src/hydra-queue-runner/nar-extractor.cc +++ b/src/hydra-queue-runner/nar-extractor.cc @@ -11,29 +11,28 @@ struct Extractor : NARParseVisitor { class MyFileHandle : public FileHandle { - NarMemberData * memberData; + NarMemberData & memberData; uint64_t expectedSize; std::unique_ptr hashSink; public: - MyFileHandle(NarMemberData * memberData, uint64_t size) : memberData(memberData) + MyFileHandle(NarMemberData & memberData, uint64_t size) : memberData(memberData), expectedSize(size) { - expectedSize = size; hashSink = std::make_unique(HashType::SHA256); } void receiveContents(std::string_view data) override { - *memberData->fileSize += data.size(); + *memberData.fileSize += data.size(); (*hashSink)(data); - if (memberData->contents) { - memberData->contents->append(data); + if (memberData.contents) { + memberData.contents->append(data); } - assert(memberData->fileSize <= expectedSize); - if (memberData->fileSize == expectedSize) { + assert(memberData.fileSize <= expectedSize); + if (memberData.fileSize == expectedSize) { auto [hash, len] = hashSink->finish(); - assert(memberData->fileSize == len); - memberData->sha256 = hash; + assert(memberData.fileSize == len); + memberData.sha256 = hash; hashSink.reset(); } } @@ -65,7 +64,7 @@ struct Extractor : NARParseVisitor .contents = filesToKeep.count(path) ? std::optional("") : std::nullopt, }).first->second; - return std::unique_ptr(new MyFileHandle{memberData, size}); + return std::make_unique(*memberData, size); } void createSymlink(const Path & path, const std::string & target) override