Lisandro Dalcin wrote: > On Wed, Sep 10, 2008 at 12:53 PM, Stefan Behnel <[EMAIL PROTECTED]> wrote: >> Lisandro Dalcin wrote: >>> On Wed, Sep 10, 2008 at 11:35 AM, Stefan Behnel <[EMAIL PROTECTED]> >>> wrote: >>>> This specific case is easy to handle as we can replace >>>> PyObject_GetAttrString() by the equivalent PyObject_GetAttr() call and >>>> create the Python string ourselves (which would normally happen inside >>>> of PyObject_GetAttrString). >>> As a reminder, please use PyString_InternFromString() (or the py3k >>> equivalent). >> I considered doing that and rejected it as I do not see the gain in >> re-re-building the Python string instead of creating it once. Why do you >> think this is necessary? > > Well, this is the way that PyObject_GetAttrString() is implemented. If > the call ends-up doing many dicts lookups (think about the chain > instance->class->[intermediate_class]->base_class), then using a > interned string is much faster (as string comparison ends-up being a > pointer comparison). In short, I believe this is a good optimization > if Cython wants its own version of PyObject_GetAttrString() > implemented in terms of PyObject_GetAttr().
I think Stefan is referring to a different approach: The string will be created at module startup time and held on to. So your point is valid but there's an even better approach :-) (assuming here that the module startup interns the string, which seems very very likely but I didn't check it). -- Dag Sverre _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
