aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/primops/context.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2022-01-04 17:39:16 +0100
committerEelco Dolstra <edolstra@gmail.com>2022-01-04 18:00:33 +0100
commit6d9a6d2cc3a20c9047436d174c9f91a2223da220 (patch)
tree2bf36cb443a80f56db38e10c8afe2c749ff3bdcc /src/libexpr/primops/context.cc
parent1ffacad8a5201713659d5e18db47b2020bdc6aa1 (diff)
Ensure that attrsets are sorted
Previously you had to remember to call value->attrs->sort() after populating value->attrs. Now there is a BindingsBuilder helper that wraps Bindings and ensures that sort() is called before you can use it.
Diffstat (limited to 'src/libexpr/primops/context.cc')
-rw-r--r--src/libexpr/primops/context.cc21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/libexpr/primops/context.cc b/src/libexpr/primops/context.cc
index 20545afd0..ab08303d8 100644
--- a/src/libexpr/primops/context.cc
+++ b/src/libexpr/primops/context.cc
@@ -103,27 +103,26 @@ static void prim_getContext(EvalState & state, const Pos & pos, Value * * args,
}
}
- state.mkAttrs(v, contextInfos.size());
+ auto attrs = state.buildBindings(contextInfos.size());
auto sPath = state.symbols.create("path");
auto sAllOutputs = state.symbols.create("allOutputs");
for (const auto & info : contextInfos) {
- auto & infoVal = *state.allocAttr(v, state.symbols.create(info.first));
- state.mkAttrs(infoVal, 3);
+ auto infoAttrs = state.buildBindings(3);
if (info.second.path)
- mkBool(*state.allocAttr(infoVal, sPath), true);
+ mkBool(infoAttrs.alloc(sPath), true);
if (info.second.allOutputs)
- mkBool(*state.allocAttr(infoVal, sAllOutputs), true);
+ mkBool(infoAttrs.alloc(sAllOutputs), true);
if (!info.second.outputs.empty()) {
- auto & outputsVal = *state.allocAttr(infoVal, state.sOutputs);
+ auto & outputsVal = infoAttrs.alloc(state.sOutputs);
state.mkList(outputsVal, info.second.outputs.size());
- size_t i = 0;
- for (const auto & output : info.second.outputs)
- mkString(*(outputsVal.listElems()[i++] = state.allocValue()), output);
+ for (const auto & [i, output] : enumerate(info.second.outputs))
+ (outputsVal.listElems()[i] = state.allocValue())->mkString(output);
}
- infoVal.attrs->sort();
+ attrs.alloc(info.first).mkAttrs(infoAttrs);
}
- v.attrs->sort();
+
+ v.mkAttrs(attrs);
}
static RegisterPrimOp primop_getContext("__getContext", 1, prim_getContext);