Tiny optimisation in the filter primop

This commit is contained in:
Eelco Dolstra 2012-12-04 17:22:20 +01:00
parent 094a08f839
commit 3100b29fc5

View file

@ -950,16 +950,23 @@ static void prim_filter(EvalState & state, Value * * args, Value & v)
Value * vs[args[1]->list.length]; Value * vs[args[1]->list.length];
unsigned int k = 0; unsigned int k = 0;
bool same = true;
for (unsigned int n = 0; n < args[1]->list.length; ++n) { for (unsigned int n = 0; n < args[1]->list.length; ++n) {
Value res; Value res;
state.callFunction(*args[0], *args[1]->list.elems[n], res); state.callFunction(*args[0], *args[1]->list.elems[n], res);
if (state.forceBool(res)) if (state.forceBool(res))
vs[k++] = args[1]->list.elems[n]; vs[k++] = args[1]->list.elems[n];
else
same = false;
} }
if (same)
v = *args[1];
else {
state.mkList(v, k); state.mkList(v, k);
for (unsigned int n = 0; n < k; ++n) v.list.elems[n] = vs[n]; for (unsigned int n = 0; n < k; ++n) v.list.elems[n] = vs[n];
} }
}
/* Return true if a list contains a given element. */ /* Return true if a list contains a given element. */