[Python-Dev] Re: [Bug #121013] Bug in <stringobject>.join(<unicodestring>)

Fredrik Lundh fredrik@effbot.org
Mon, 27 Nov 2000 22:41:17 +0100

Michael Hudson wrote:
> > Fredrik's PySequence_Fast_* APIs look interesting, BTW. Should be
> > used more often :-)
> Yes.  But they're pretty new, aren't they?  I find them a bit
> unsatisfactory that it's not possible to hoist the type check out of
> the inner loop.

if you can figure out a way to do that with C macros,
I'd love to see it...

on the other hand, PySequence_Fast guarantees that the
returned object is either a list or a tuple, so you can easily
move the test outside the loop yourself:

    if (PyTuple_Check(seq))
        for (...)
            item = PyTuple_GET_ITEM(seq, i)
        for (...)
            item = PyList_GET_ITEM(seq, i)

> Still, it seems my PII's branch predictor nails that one... (i.e. changing
> it so that it didn't check inside the loop made naff-all difference to the
> running time).

yeah, the type isn't likely to change inside the loop...