[Python-Dev] other "magic strings" issues
Martin v. Löwis
martin at v.loewis.de
Sat Nov 8 04:53:19 EST 2003
Alex Martelli <aleaxit at yahoo.com> writes:
> I dunno -- it seems that (on a toy case where an 'in' test takes 0.25 usec
> and an .isdigit takes 0.52 to 0.55) we can shave the time to 0.39, about
> in-between, by avoiding the generation of a bound-method. Now of course
> saving 25% or so isn't huge, but maybe it's still worth it...?
If you can avoid creating bound methods in the general case, that
would be a good thing. Even avoiding them for for strings only would
be valuable, although I would then ask that you extend your strategy
> should be able to print two distinct values for appropriate values of
> xx and locale changes, right?
> Hmmm -- if supporting this usage is crucial
> then indeed we can't avoid generating a boundmethod (for .islower and
> other locale-aware .is* methods), because the "return a function" approach
> is basically evaluating the function at attribute-access time... if locale
> changes between the attribute-access time and the moment of the call,
> then the result may not be as desired.
It's not crucial, but it would be an incompatible change to change it.
However, this is irrelevant with respect to bound methods. The
locale-awareness is in the code of the function, so if you manage to
invoke that at the point of the call (instead of caching its result),
then it would still be compatible.
More information about the Python-Dev