[Python-Dev] Type of range object members
Neal Norwitz
nnorwitz at gmail.com
Thu Aug 17 07:57:54 CEST 2006
On 8/16/06, Phillip J. Eby <pje at telecommunity.com> wrote:
>
> It seems to me that you could drop the FAST_SUBCLASS bit, since none of the
> other bits will be set if it is not a subclass of a builtin. That would
> free up one flag bit -- perhaps usable for that BaseException flag Guido
> wants. :)
:-) Right, I'm not using the bit currently. I was thinking that it
would be interesting to change the CheckExact versions to also use
this. It's a little more work, but you lose the second comparison for
Check. I expect that it would be slower, but I was just curious.
So with the patch we currently have:
#define PyInt_CheckExact(op) ((op)->ob_type == &PyInt_Type)
#define PyInt_Check(op) (PyInt_CheckExact(op) || \
PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_INT_SUBCLASS))
But we could have something like:
#define PyInt_CheckExact(op) (PyType_FastClass(op,Py_TPFLAGS_INT_CLASS))
#define PyInt_Check(op) (PyType_FastSubclass(op,Py_TPFLAGS_INT_SUBCLASS))
It would change the CheckExact()s from: op->ob_type ==
global-variable, to: op->ob_type & CONSTANT == CONSTANT. Check would
be the same as the CheckExact, just with different constants. The
Check version would then drop the || condition.
I might play with this at the sprint next week. It does seem to make
sense to do BaseException too. It will take 4 or 5 bits to handle the
current ones plus BaseException, which we can easily spare in
tp_flags.
n
More information about the Python-Dev
mailing list