diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-12-04T16·22+0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-12-04T16·22+0100 |
commit | 3100b29fc51b46c76f6aca1fffc62881ca10de64 (patch) | |
tree | 888c1098ef8e9fd48d5dc51289c5a41923228d16 | |
parent | 094a08f8396c913b6023ae2bf1c6615470e7cc45 (diff) |
Tiny optimisation in the filter primop
-rw-r--r-- | src/libexpr/primops.cc | 11 |
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]; + } } |