mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 22:16:16 +02:00
Merge pull request #9681 from edolstra/eval-optimisations
Optimize empty list constants
This commit is contained in:
commit
315aade89d
3 changed files with 17 additions and 0 deletions
|
@ -554,6 +554,8 @@ EvalState::EvalState(
|
||||||
|
|
||||||
static_assert(sizeof(Env) <= 16, "environment must be <= 16 bytes");
|
static_assert(sizeof(Env) <= 16, "environment must be <= 16 bytes");
|
||||||
|
|
||||||
|
vEmptyList.mkList(0);
|
||||||
|
|
||||||
/* Initialise the Nix expression search path. */
|
/* Initialise the Nix expression search path. */
|
||||||
if (!evalSettings.pureEval) {
|
if (!evalSettings.pureEval) {
|
||||||
for (auto & i : _searchPath.elements)
|
for (auto & i : _searchPath.elements)
|
||||||
|
@ -1385,6 +1387,15 @@ void ExprList::eval(EvalState & state, Env & env, Value & v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Value * ExprList::maybeThunk(EvalState & state, Env & env)
|
||||||
|
{
|
||||||
|
if (elems.empty()) {
|
||||||
|
return &state.vEmptyList;
|
||||||
|
}
|
||||||
|
return Expr::maybeThunk(state, env);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ExprVar::eval(EvalState & state, Env & env, Value & v)
|
void ExprVar::eval(EvalState & state, Env & env, Value & v)
|
||||||
{
|
{
|
||||||
Value * v2 = state.lookupVar(&env, *this, false);
|
Value * v2 = state.lookupVar(&env, *this, false);
|
||||||
|
|
|
@ -213,6 +213,11 @@ public:
|
||||||
|
|
||||||
Bindings emptyBindings;
|
Bindings emptyBindings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty list constant.
|
||||||
|
*/
|
||||||
|
Value vEmptyList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The accessor for the root filesystem.
|
* The accessor for the root filesystem.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -303,6 +303,7 @@ struct ExprList : Expr
|
||||||
std::vector<Expr *> elems;
|
std::vector<Expr *> elems;
|
||||||
ExprList() { };
|
ExprList() { };
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
|
Value * maybeThunk(EvalState & state, Env & env) override;
|
||||||
|
|
||||||
PosIdx getPos() const override
|
PosIdx getPos() const override
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue