Tiny optimisation in the filter primop
This commit is contained in:
parent
094a08f839
commit
3100b29fc5
|
@ -950,15 +950,22 @@ 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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue