Skip to content

Commit 263a818

Browse files
authored
Merge pull request #12296 from DeterminateSystems/release-source-early
addMultipleToStore(): Move pathsToCopy
2 parents 991be65 + 2669e4a commit 263a818

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

src/libstore/remote-store.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,21 +534,25 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source,
534534

535535

536536
void RemoteStore::addMultipleToStore(
537-
PathsSource & pathsToCopy,
537+
PathsSource && pathsToCopy,
538538
Activity & act,
539539
RepairFlag repair,
540540
CheckSigsFlag checkSigs)
541541
{
542542
auto source = sinkToSource([&](Sink & sink) {
543543
sink << pathsToCopy.size();
544-
for (auto & [pathInfo, pathSource] : pathsToCopy) {
544+
// Reverse, so we can release memory at the original start
545+
std::reverse(pathsToCopy.begin(), pathsToCopy.end());
546+
while (!pathsToCopy.empty()) {
547+
auto & [pathInfo, pathSource] = pathsToCopy.back();
545548
WorkerProto::Serialise<ValidPathInfo>::write(*this,
546549
WorkerProto::WriteConn {
547550
.to = sink,
548551
.version = 16,
549552
},
550553
pathInfo);
551554
pathSource->drainInto(sink);
555+
pathsToCopy.pop_back();
552556
}
553557
});
554558

src/libstore/remote-store.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public:
102102
CheckSigsFlag checkSigs) override;
103103

104104
void addMultipleToStore(
105-
PathsSource & pathsToCopy,
105+
PathsSource && pathsToCopy,
106106
Activity & act,
107107
RepairFlag repair,
108108
CheckSigsFlag checkSigs) override;

src/libstore/store-api.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ StorePath Store::addToStore(
223223
}
224224

225225
void Store::addMultipleToStore(
226-
PathsSource & pathsToCopy,
226+
PathsSource && pathsToCopy,
227227
Activity & act,
228228
RepairFlag repair,
229229
CheckSigsFlag checkSigs)
@@ -1138,7 +1138,7 @@ std::map<StorePath, StorePath> copyPaths(
11381138
pathsToCopy.push_back(std::pair{infoForDst, std::move(source)});
11391139
}
11401140

1141-
dstStore.addMultipleToStore(pathsToCopy, act, repair, checkSigs);
1141+
dstStore.addMultipleToStore(std::move(pathsToCopy), act, repair, checkSigs);
11421142

11431143
return pathsMap;
11441144
}

src/libstore/store-api.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public:
425425
CheckSigsFlag checkSigs = CheckSigs);
426426

427427
virtual void addMultipleToStore(
428-
PathsSource & pathsToCopy,
428+
PathsSource && pathsToCopy,
429429
Activity & act,
430430
RepairFlag repair = NoRepair,
431431
CheckSigsFlag checkSigs = CheckSigs);

0 commit comments

Comments
 (0)