mirror of
https://github.com/NixOS/nix
synced 2025-06-24 22:11:15 +02:00
libexpr: Use attrs.alreadySorted()
in primop_functionArgs
Formals are already sorted as it's an invariant of `Formals`.
This commit is contained in:
parent
8c10104e9e
commit
a4bfd559f1
2 changed files with 12 additions and 3 deletions
|
@ -306,6 +306,9 @@ struct Formal
|
|||
struct Formals
|
||||
{
|
||||
typedef std::vector<Formal> Formals_;
|
||||
/**
|
||||
* @pre Sorted according to predicate (std::tie(a.name, a.pos) < std::tie(b.name, b.pos)).
|
||||
*/
|
||||
Formals_ formals;
|
||||
bool ellipsis;
|
||||
|
||||
|
|
|
@ -3148,10 +3148,16 @@ static void prim_functionArgs(EvalState & state, const PosIdx pos, Value * * arg
|
|||
return;
|
||||
}
|
||||
|
||||
auto attrs = state.buildBindings(args[0]->payload.lambda.fun->formals->formals.size());
|
||||
for (auto & i : args[0]->payload.lambda.fun->formals->formals)
|
||||
const auto &formals = args[0]->payload.lambda.fun->formals->formals;
|
||||
auto attrs = state.buildBindings(formals.size());
|
||||
for (auto & i : formals)
|
||||
attrs.insert(i.name, state.getBool(i.def), i.pos);
|
||||
v.mkAttrs(attrs);
|
||||
/* Optimization: avoid sorting bindings. `formals` must already be sorted according to
|
||||
(std::tie(a.name, a.pos) < std::tie(b.name, b.pos)) predicate, so the following assertion
|
||||
always holds:
|
||||
assert(std::is_sorted(attrs.alreadySorted()->begin(), attrs.alreadySorted()->end()));
|
||||
.*/
|
||||
v.mkAttrs(attrs.alreadySorted());
|
||||
}
|
||||
|
||||
static RegisterPrimOp primop_functionArgs({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue