From e068f49f7dc59788cf356acfc77db614db6b28f0 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Tue, 16 Jul 2013 08:43:54 -0400 Subject: Avoid thunks when a fromWith var can be looked up without evaluation Signed-off-by: Shea Levy --- src/libexpr/eval.cc | 14 +++++++------- src/libexpr/eval.hh | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/libexpr') diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 76bace1d4..0139f4eb0 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -304,13 +304,15 @@ void mkPath(Value & v, const char * s) } -inline Value * EvalState::lookupVar(Env * env, const VarRef & var) +inline Value * EvalState::lookupVar(Env * env, const VarRef & var, bool noEval) { for (unsigned int l = var.level; l; --l, env = env->up) ; if (var.fromWith) { while (1) { if (env->values[0] == NULL) { + if (noEval) + return NULL; env->values[0] = allocValue(); evalAttrs(*env->up, env->withAttrs, *env->values[0]); } @@ -409,12 +411,10 @@ unsigned long nrAvoided = 0; Value * ExprVar::maybeThunk(EvalState & state, Env & env) { - if (!info.fromWith) { - Value * v = state.lookupVar(&env, info); - /* The value might not be initialised in the environment yet. - In that case, ignore it. */ - if (v) { nrAvoided++; return v; } - } + Value * v = state.lookupVar(&env, info, true); + /* The value might not be initialised in the environment yet. + In that case, ignore it. */ + if (v) { nrAvoided++; return v; } return Expr::maybeThunk(state, env); } diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 0e4ad3db2..c820b28f4 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -206,7 +206,7 @@ private: void addPrimOp(const string & name, unsigned int arity, PrimOpFun primOp); - inline Value * lookupVar(Env * env, const VarRef & var); + inline Value * lookupVar(Env * env, const VarRef & var, bool noEval = false); friend class ExprVar; friend class ExprAttrs; -- cgit v1.2.3