summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-12-04 17:22:20 +0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-12-04 17:22:20 +0100
commit3100b29fc51b46c76f6aca1fffc62881ca10de64 (patch)
tree888c1098ef8e9fd48d5dc51289c5a41923228d16 /src
parent094a08f8396c913b6023ae2bf1c6615470e7cc45 (diff)
downloadguix-3100b29fc51b46c76f6aca1fffc62881ca10de64.tar.gz
Tiny optimisation in the filter primop
Diffstat (limited to 'src')
-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 db27b716b0..f8f893d696 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];
+    }
 }