Avoid thunks when a fromWith var can be looked up without evaluation

Signed-off-by: Shea Levy <shea@shealevy.com>
This commit is contained in:
Shea Levy 2013-07-16 08:43:54 -04:00 committed by Eelco Dolstra
parent 20866a7031
commit e068f49f7d
2 changed files with 8 additions and 8 deletions

View file

@ -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) ; for (unsigned int l = var.level; l; --l, env = env->up) ;
if (var.fromWith) { if (var.fromWith) {
while (1) { while (1) {
if (env->values[0] == NULL) { if (env->values[0] == NULL) {
if (noEval)
return NULL;
env->values[0] = allocValue(); env->values[0] = allocValue();
evalAttrs(*env->up, env->withAttrs, *env->values[0]); evalAttrs(*env->up, env->withAttrs, *env->values[0]);
} }
@ -409,12 +411,10 @@ unsigned long nrAvoided = 0;
Value * ExprVar::maybeThunk(EvalState & state, Env & env) Value * ExprVar::maybeThunk(EvalState & state, Env & env)
{ {
if (!info.fromWith) { Value * v = state.lookupVar(&env, info, true);
Value * v = state.lookupVar(&env, info); /* The value might not be initialised in the environment yet.
/* The value might not be initialised in the environment yet. In that case, ignore it. */
In that case, ignore it. */ if (v) { nrAvoided++; return v; }
if (v) { nrAvoided++; return v; }
}
return Expr::maybeThunk(state, env); return Expr::maybeThunk(state, env);
} }

View file

@ -206,7 +206,7 @@ private:
void addPrimOp(const string & name, void addPrimOp(const string & name,
unsigned int arity, PrimOpFun primOp); 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 ExprVar;
friend class ExprAttrs; friend class ExprAttrs;