mirror of
https://github.com/NixOS/nix.git
synced 2025-11-20 01:09:37 +01:00
Cleanup: Use C++23 "explicit this" for recursive lambdas
Try to pass by reference where possible. Co-authored-by: Sergei Zimmerman <sergei@zimmerman.foo>
This commit is contained in:
parent
3b2186e1c8
commit
1507843f6c
15 changed files with 60 additions and 112 deletions
|
|
@ -1391,8 +1391,7 @@ void adl_serializer<Derivation>::to_json(json & res, const Derivation & d)
|
|||
}
|
||||
|
||||
{
|
||||
std::function<nlohmann::json(const DerivedPathMap<StringSet>::ChildNode &)> doInput;
|
||||
doInput = [&](const auto & inputNode) {
|
||||
auto doInput = [&](this const auto & doInput, const auto & inputNode) -> nlohmann::json {
|
||||
auto value = nlohmann::json::object();
|
||||
value["outputs"] = inputNode.value;
|
||||
{
|
||||
|
|
@ -1454,8 +1453,7 @@ Derivation adl_serializer<Derivation>::from_json(const json & _json, const Exper
|
|||
}
|
||||
|
||||
try {
|
||||
std::function<DerivedPathMap<StringSet>::ChildNode(const nlohmann::json &)> doInput;
|
||||
doInput = [&](const auto & _json) {
|
||||
auto doInput = [&](this const auto & doInput, const auto & _json) -> DerivedPathMap<StringSet>::ChildNode {
|
||||
auto & json = getObject(_json);
|
||||
DerivedPathMap<StringSet>::ChildNode node;
|
||||
node.value = getStringSet(valueAt(json, "outputs"));
|
||||
|
|
|
|||
|
|
@ -126,13 +126,13 @@ MissingPaths Store::queryMissing(const std::vector<DerivedPath> & targets)
|
|||
|
||||
std::function<void(DerivedPath)> doPath;
|
||||
|
||||
std::function<void(ref<SingleDerivedPath>, const DerivedPathMap<StringSet>::ChildNode &)> enqueueDerivedPaths;
|
||||
|
||||
enqueueDerivedPaths = [&](ref<SingleDerivedPath> inputDrv, const DerivedPathMap<StringSet>::ChildNode & inputNode) {
|
||||
auto enqueueDerivedPaths = [&](this auto self,
|
||||
ref<SingleDerivedPath> inputDrv,
|
||||
const DerivedPathMap<StringSet>::ChildNode & inputNode) -> void {
|
||||
if (!inputNode.value.empty())
|
||||
pool.enqueue(std::bind(doPath, DerivedPath::Built{inputDrv, inputNode.value}));
|
||||
for (const auto & [outputName, childNode] : inputNode.childMap)
|
||||
enqueueDerivedPaths(make_ref<SingleDerivedPath>(SingleDerivedPath::Built{inputDrv, outputName}), childNode);
|
||||
self(make_ref<SingleDerivedPath>(SingleDerivedPath::Built{inputDrv, outputName}), childNode);
|
||||
};
|
||||
|
||||
auto mustBuildDrv = [&](const StorePath & drvPath, const Derivation & drv) {
|
||||
|
|
@ -350,9 +350,9 @@ drvOutputReferences(Store & store, const Derivation & drv, const StorePath & out
|
|||
|
||||
std::set<Realisation> inputRealisations;
|
||||
|
||||
std::function<void(const StorePath &, const DerivedPathMap<StringSet>::ChildNode &)> accumRealisations;
|
||||
|
||||
accumRealisations = [&](const StorePath & inputDrv, const DerivedPathMap<StringSet>::ChildNode & inputNode) {
|
||||
auto accumRealisations = [&](this auto & self,
|
||||
const StorePath & inputDrv,
|
||||
const DerivedPathMap<StringSet>::ChildNode & inputNode) -> void {
|
||||
if (!inputNode.value.empty()) {
|
||||
auto outputHashes = staticOutputHashes(evalStore, evalStore.readDerivation(inputDrv));
|
||||
for (const auto & outputName : inputNode.value) {
|
||||
|
|
@ -372,7 +372,7 @@ drvOutputReferences(Store & store, const Derivation & drv, const StorePath & out
|
|||
auto d = makeConstantStorePathRef(inputDrv);
|
||||
for (const auto & [outputName, childNode] : inputNode.childMap) {
|
||||
SingleDerivedPath next = SingleDerivedPath::Built{d, outputName};
|
||||
accumRealisations(
|
||||
self(
|
||||
// TODO deep resolutions for dynamic derivations, issue #8947, would go here.
|
||||
resolveDerivedPath(store, next, evalStore_),
|
||||
childNode);
|
||||
|
|
|
|||
|
|
@ -144,11 +144,7 @@ struct NarAccessor : public SourceAccessor
|
|||
NarAccessor(const nlohmann::json & listing, GetNarBytes getNarBytes)
|
||||
: getNarBytes(getNarBytes)
|
||||
{
|
||||
using json = nlohmann::json;
|
||||
|
||||
std::function<void(NarMember &, const json &)> recurse;
|
||||
|
||||
recurse = [&](NarMember & member, const json & v) {
|
||||
[&](this const auto & recurse, NarMember & member, const nlohmann::json & v) -> void {
|
||||
std::string type = v["type"];
|
||||
|
||||
if (type == "directory") {
|
||||
|
|
@ -167,9 +163,7 @@ struct NarAccessor : public SourceAccessor
|
|||
member.target = v.value("target", "");
|
||||
} else
|
||||
return;
|
||||
};
|
||||
|
||||
recurse(root, listing);
|
||||
}(root, listing);
|
||||
}
|
||||
|
||||
NarMember * find(const CanonPath & path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue