From 7f1af270ddffa1cd6d18c167bcebe56b93bfd127 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 10 Jan 2023 15:08:46 +0100 Subject: Clean up toDerivedPaths() logic --- src/libcmd/installables.cc | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'src/libcmd/installables.cc') diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 409afd762..c0db2a715 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -478,11 +478,9 @@ struct InstallableAttrPath : InstallableValue DrvInfos drvInfos; getDerivations(*state, *v, "", autoArgs, drvInfos, false); - DerivedPathsWithInfo res; - // Backward compatibility hack: group results by drvPath. This // helps keep .all output together. - std::map byDrvPath; + std::map byDrvPath; for (auto & drvInfo : drvInfos) { auto drvPath = drvInfo.queryDrvPath(); @@ -497,21 +495,16 @@ struct InstallableAttrPath : InstallableValue for (auto & output : drvInfo.queryOutputs(false, std::get_if(&outputsSpec))) outputsToInstall.insert(output.first); - auto i = byDrvPath.find(*drvPath); - if (i == byDrvPath.end()) { - byDrvPath[*drvPath] = res.size(); - res.push_back({ - .path = DerivedPath::Built { - .drvPath = std::move(*drvPath), - .outputs = std::move(outputsToInstall), - } - }); - } else { - for (auto & output : outputsToInstall) - std::get(res[i->second].path).outputs.insert(output); - } + auto derivedPath = byDrvPath.emplace(*drvPath, DerivedPath::Built { .drvPath = *drvPath }).first; + + for (auto & output : outputsToInstall) + derivedPath->second.outputs.insert(output); } + DerivedPathsWithInfo res; + for (auto & [_, info] : byDrvPath) + res.push_back({ .path = { info } }); + return res; } }; -- cgit v1.2.3