[pypy-dev] [pypy-commit] pypy default: Unroll list.count() when the list is virtual or very small and constant lenght

Carl Friedrich Bolz cfbolz at gmx.de
Fri Aug 30 14:31:18 CEST 2013


On 30/08/13 12:58, Amaury Forgeot d'Arc wrote:
> 
> 2013/8/30 Carl Friedrich Bolz <cfbolz at gmx.de <mailto:cfbolz at gmx.de>>
> 
>     Hi Alex,
> 
>     please revert this change, it can lead to combinatorial explosion: it
>     can give a bridge per pattern of where in the list the object is found.
> 
> 
> Doesn't list.count() traverse all the list in all cases?

It looks like this:

        count = 0
        i = 0
        while i < self.length():
            if space.eq_w(self.getitem(i), w_value):
                count += 1
            i += 1

So there's a guard_true/false for every item.

Note that even changing to:

count += space.eq_w(self.getitem(i), w_value)

does not fix this, because the guard is coming from inside space.istrue,
or space.eq

Cheers,

Carl Friedrich



More information about the pypy-dev mailing list