about summary refs log tree commit diff
path: root/src/libexpr/primops.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r--src/libexpr/primops.cc11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index db27b716b023..f8f893d69683 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -950,15 +950,22 @@ static void prim_filter(EvalState & state, Value * * args, Value & v)
     Value * vs[args[1]->list.length];
     unsigned int k = 0;
 
+    bool same = true;
     for (unsigned int n = 0; n < args[1]->list.length; ++n) {
         Value res;
         state.callFunction(*args[0], *args[1]->list.elems[n], res);
         if (state.forceBool(res))
             vs[k++] = args[1]->list.elems[n];
+        else
+            same = false;
     }
 
-    state.mkList(v, k);
-    for (unsigned int n = 0; n < k; ++n) v.list.elems[n] = vs[n];
+    if (same)
+        v = *args[1];
+    else {
+        state.mkList(v, k);
+        for (unsigned int n = 0; n < k; ++n) v.list.elems[n] = vs[n];
+    }
 }