about summary refs log tree commit diff
path: root/src/libexpr
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2018-07-23T07·19+0200
committerGitHub <noreply@github.com>2018-07-23T07·19+0200
commit925053e97458374a32974d3a85cb59dc120b3ca2 (patch)
treefd4d6364409394f8df1cd42a39cfb3cd4b9e76e7 /src/libexpr
parent1b34b69b45106e5bfdbdc0201d3ff4dcd36632f0 (diff)
parente2b114cfe19c28bfd9fe95e1aa97aa154b904002 (diff)
Merge pull request #2302 from volth/patch-3
prim_foldlStrict: call forceValue() before value is copied
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/primops.cc13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index e71e3a6d46cb..311a32b0b30f 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];
+    }
 }