Skip to content

Commit

Permalink
prim_foldlStrict: call forceValue() before value is copied
Browse files Browse the repository at this point in the history
forceValue() were called after a value is copied effectively forcing only one of the copies keeping another copy not evaluated.
This resulted in its evaluation of the same lazy value more than once (the number of hits is not big though)
  • Loading branch information
volth committed Jul 21, 2018
1 parent 1b34b69 commit e2b114c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1508,19 +1508,20 @@ static void prim_foldlStrict(EvalState & state, const Pos & pos, Value * * args,
state.forceFunction(*args[0], pos);
state.forceList(*args[2], pos);

Value * vCur = args[1];
if (args[2]->listSize()) {
Value * vCur = args[1];

if (args[2]->listSize())
for (unsigned int n = 0; n < args[2]->listSize(); ++n) {
Value vTmp;
state.callFunction(*args[0], *vCur, vTmp, pos);
vCur = n == args[2]->listSize() - 1 ? &v : state.allocValue();
state.callFunction(vTmp, *args[2]->listElems()[n], *vCur, pos);
}
else
v = *vCur;

state.forceValue(v);
state.forceValue(v);
} else {
state.forceValue(*args[1]);
v = *args[1];
}
}


Expand Down

0 comments on commit e2b114c

Please sign in to comment.