Variation of patch # 1624059 to speed up checking if an object is a subclass

of some of the common builtin types.

Use a bit in tp_flags for each common builtin type.  Check the bit
to determine if any instance is a subclass of these common types.
The check avoids a function call and O(n) search of the base classes.
The check is done in the various Py*_Check macros rather than calling
PyType_IsSubtype().

All the bits are set in tp_flags when the type is declared
in the Objects/*object.c files because PyType_Ready() is not called
for all the types.  Should PyType_Ready() be called for all types?
If so and the change is made, the changes to the Objects/*object.c files
can be reverted (remove setting the tp_flags).  Objects/typeobject.c
would also have to be modified to add conditions
for Py*_CheckExact() in addition to each the PyType_IsSubtype check.
This commit is contained in:
Neal Norwitz 2007-02-25 19:44:48 +00:00
parent 5a3e812444
commit ee3a1b5244
18 changed files with 61 additions and 22 deletions

View file

@ -55,7 +55,8 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyBaseString_Type;
PyAPI_DATA(PyTypeObject) PyString_Type;
#define PyString_Check(op) PyObject_TypeCheck(op, &PyString_Type)
#define PyString_Check(op) \
PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_STRING_SUBCLASS)
#define PyString_CheckExact(op) ((op)->ob_type == &PyString_Type)
PyAPI_FUNC(PyObject *) PyString_FromStringAndSize(const char *, Py_ssize_t);