From 3100b29fc51b46c76f6aca1fffc62881ca10de64 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 4 Dec 2012 17:22:20 +0100 Subject: [PATCH] Tiny optimisation in the filter primop --- src/libexpr/primops.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index db27b716b..f8f893d69 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]; + } }