From 3f7519526f7e2cd3ede01c3910fbfe2ddf0f051f Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Wed, 25 Sep 2024 23:57:46 +0200 Subject: [PATCH] libstore: have makeLocalDerivationGoal return unique_ptrs these can be unique rather than shared because shared_ptr has a converting constructor. preparatory refactor for something else and not necessary on its own, and the extra allocations we must do for shared_ptr control blocks isn't usually relevant anyway. Change-Id: I5391715545240c6ec8e83a031206edafdfc6462f --- src/libstore/build/local-derivation-goal.hh | 4 ++-- src/libstore/build/worker.cc | 10 +++++----- src/libstore/build/worker.hh | 2 +- src/libstore/platform.cc | 20 ++++++++++---------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/libstore/build/local-derivation-goal.hh b/src/libstore/build/local-derivation-goal.hh index 6239129ab..52b7d4c2e 100644 --- a/src/libstore/build/local-derivation-goal.hh +++ b/src/libstore/build/local-derivation-goal.hh @@ -182,7 +182,7 @@ struct LocalDerivationGoal : public DerivationGoal * Create a LocalDerivationGoal without an on-disk .drv file, * possibly a platform-specific subclass */ - static std::shared_ptr makeLocalDerivationGoal( + static std::unique_ptr makeLocalDerivationGoal( const StorePath & drvPath, const OutputsSpec & wantedOutputs, Worker & worker, @@ -194,7 +194,7 @@ struct LocalDerivationGoal : public DerivationGoal * Create a LocalDerivationGoal for an on-disk .drv file, * possibly a platform-specific subclass */ - static std::shared_ptr makeLocalDerivationGoal( + static std::unique_ptr makeLocalDerivationGoal( const StorePath & drvPath, const BasicDerivation & drv, const OutputsSpec & wantedOutputs, diff --git a/src/libstore/build/worker.cc b/src/libstore/build/worker.cc index 68071a94c..18cdde63a 100644 --- a/src/libstore/build/worker.cc +++ b/src/libstore/build/worker.cc @@ -55,7 +55,7 @@ Worker::~Worker() std::pair, kj::Promise> Worker::makeDerivationGoalCommon( const StorePath & drvPath, const OutputsSpec & wantedOutputs, - std::function()> mkDrvGoal) + std::function()> mkDrvGoal) { auto & goal_weak = derivationGoals[drvPath]; std::shared_ptr goal = goal_weak.goal.lock(); @@ -78,9 +78,9 @@ std::pair, kj::Promise> Worker::makeDeriva return makeDerivationGoalCommon( drvPath, wantedOutputs, - [&]() -> std::shared_ptr { + [&]() -> std::unique_ptr { return !dynamic_cast(&store) - ? std::make_shared( + ? std::make_unique( drvPath, wantedOutputs, *this, running, buildMode ) : LocalDerivationGoal::makeLocalDerivationGoal( @@ -101,9 +101,9 @@ std::pair, kj::Promise> Worker::makeBasicD return makeDerivationGoalCommon( drvPath, wantedOutputs, - [&]() -> std::shared_ptr { + [&]() -> std::unique_ptr { return !dynamic_cast(&store) - ? std::make_shared( + ? std::make_unique( drvPath, drv, wantedOutputs, *this, running, buildMode ) : LocalDerivationGoal::makeLocalDerivationGoal( diff --git a/src/libstore/build/worker.hh b/src/libstore/build/worker.hh index 925d289bf..46adaa145 100644 --- a/src/libstore/build/worker.hh +++ b/src/libstore/build/worker.hh @@ -245,7 +245,7 @@ public: private: std::pair, kj::Promise> makeDerivationGoalCommon( const StorePath & drvPath, const OutputsSpec & wantedOutputs, - std::function()> mkDrvGoal); + std::function()> mkDrvGoal); std::pair, kj::Promise> makeDerivationGoal( const StorePath & drvPath, const OutputsSpec & wantedOutputs, BuildMode buildMode = bmNormal) override; diff --git a/src/libstore/platform.cc b/src/libstore/platform.cc index f2c023c82..36f8e352a 100644 --- a/src/libstore/platform.cc +++ b/src/libstore/platform.cc @@ -25,7 +25,7 @@ std::shared_ptr LocalStore::makeLocalStore(const Params & params) #endif } -std::shared_ptr LocalDerivationGoal::makeLocalDerivationGoal( +std::unique_ptr LocalDerivationGoal::makeLocalDerivationGoal( const StorePath & drvPath, const OutputsSpec & wantedOutputs, Worker & worker, @@ -34,17 +34,17 @@ std::shared_ptr LocalDerivationGoal::makeLocalDerivationGoa ) { #if __linux__ - return std::make_shared(drvPath, wantedOutputs, worker, isDependency, buildMode); + return std::make_unique(drvPath, wantedOutputs, worker, isDependency, buildMode); #elif __APPLE__ - return std::make_shared(drvPath, wantedOutputs, worker, isDependency, buildMode); + return std::make_unique(drvPath, wantedOutputs, worker, isDependency, buildMode); #elif __FreeBSD__ - return std::make_shared(drvPath, wantedOutputs, worker, isDependency, buildMode); + return std::make_unique(drvPath, wantedOutputs, worker, isDependency, buildMode); #else - return std::make_shared(drvPath, wantedOutputs, worker, isDependency, buildMode); + return std::make_unique(drvPath, wantedOutputs, worker, isDependency, buildMode); #endif } -std::shared_ptr LocalDerivationGoal::makeLocalDerivationGoal( +std::unique_ptr LocalDerivationGoal::makeLocalDerivationGoal( const StorePath & drvPath, const BasicDerivation & drv, const OutputsSpec & wantedOutputs, @@ -54,19 +54,19 @@ std::shared_ptr LocalDerivationGoal::makeLocalDerivationGoa ) { #if __linux__ - return std::make_shared( + return std::make_unique( drvPath, drv, wantedOutputs, worker, isDependency, buildMode ); #elif __APPLE__ - return std::make_shared( + return std::make_unique( drvPath, drv, wantedOutputs, worker, isDependency, buildMode ); #elif __FreeBSD__ - return std::make_shared( + return std::make_unique( drvPath, drv, wantedOutputs, worker, isDependency, buildMode ); #else - return std::make_shared( + return std::make_unique( drvPath, drv, wantedOutputs, worker, isDependency, buildMode ); #endif