Simplify isinstance coding in base.py
Brought to you by:
elie
Current code in base.py is doing:
if version_info_major < 2 and version_info_minor < 2:
checks in tight loop code. It would be more efficient
to redefine the function based on the check to use the
proper algorithm rather than to do the check within the
code.
However, that winds up with a lot of duplicated code.
Alternate approach embodied in the patch is to define a
new function _isinstance( ) which provides 2.2+
isinstance semantics regardless of Python version,
either by simply rebinding isinstance (Python 2.2+) or
by providing a backward-compatible rewrite.
Patch to base.py to define and use _isinstance function
Logged In: YES
user_id=106050
According to
http://manatee.mojam.com/~skip/python/fastpython.html#aggregate
, functions are quite expensive so I'm not sure there would
be significant gain from the _isinstance()-based solution.
Also, in the recent code (at CVS) the set() calling rate
must be not be that high.
Anyway, I've ended up 1) dup'ing verifyConstraints() code
and 2) eliminating the type verification code at set(). See
the attached patch.
Logged In: YES
user_id=34901
True, functions are expensive, but built-ins are cheap. The
Python version of the function would only have been executed
for those using obsolete versions of Python (1.5.2 being...
what... 5 years old now (1999 IIRC)), while those using 2.2
or 2.3 would have a simple C function call (eliminating the
two if checks and 2 global-variable lookups). Anyway, not
important now.
I'm working from CVS snapshots, btw, though via anonymous
CVS, so may actually be slightly stale compared to what
you're working on.