From e2b114cfe19c28bfd9fe95e1aa97aa154b904002 Mon Sep 17 00:00:00 2001 From: volth Date: Sat, 21 Jul 2018 06:44:42 +0000 Subject: prim_foldlStrict: call forceValue() before value is copied 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) --- src/libexpr/primops.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/libexpr/primops.cc') diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index e71e3a6d4..311a32b0b 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -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]; + } } -- cgit v1.2.3