diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index a62cee299..5e2f71649 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -937,6 +937,9 @@ ListBuilder::ListBuilder(EvalState & state, size_t size) state.nrListElems += size; } +Value * EvalState::getBool(bool b) { + return b ? &vTrue : &vFalse; +} unsigned long nrThunks = 0; diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index eac83fe34..f15d19653 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -650,6 +650,11 @@ public: return ListBuilder(*this, size); } + /** + * Return a boolean `Value *` without allocating. + */ + Value *getBool(bool b); + void mkThunk_(Value & v, Expr * expr); void mkPos(Value & v, PosIdx pos); diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 0f2aaa83f..d0fcfd194 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -2845,8 +2845,7 @@ static void prim_functionArgs(EvalState & state, const PosIdx pos, Value * * arg auto attrs = state.buildBindings(args[0]->lambda.fun->formals->formals.size()); for (auto & i : args[0]->lambda.fun->formals->formals) - // !!! should optimise booleans (allocate only once) - attrs.alloc(i.name, i.pos).mkBool(i.def); + attrs.insert(i.name, state.getBool(i.def), i.pos); v.mkAttrs(attrs); }