Skip to content

Commit 27d517b

Browse files
committed
Merged revisions 53875-53911 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r53899 | neal.norwitz | 2007-02-25 16:52:27 +0100 (Sun, 25 Feb 2007) | 1 line Add more details when releasing interned strings ........ r53900 | neal.norwitz | 2007-02-25 16:53:36 +0100 (Sun, 25 Feb 2007) | 1 line Whitespace only changes ........ r53901 | jeremy.hylton | 2007-02-25 16:57:45 +0100 (Sun, 25 Feb 2007) | 8 lines Fix crash in exec when unicode filename can't be decoded. I can't think of an easy way to test this behavior. It only occurs when the file system default encoding and the interpreter default encoding are different, such that you can open the file but not decode its name. ........ r53902 | jeremy.hylton | 2007-02-25 17:01:58 +0100 (Sun, 25 Feb 2007) | 2 lines Put declarations before code. ........ r53910 | fred.drake | 2007-02-25 18:56:27 +0100 (Sun, 25 Feb 2007) | 3 lines - SF patch #1657613: add documentation for the Element interface - clean up bogus use of the {datadescni} environment everywhere ........ r53911 | neal.norwitz | 2007-02-25 20:44:48 +0100 (Sun, 25 Feb 2007) | 17 lines 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. ........
1 parent 9a7e774 commit 27d517b

18 files changed

Lines changed: 236 additions & 119 deletions

Doc/lib/libetree.tex

Lines changed: 163 additions & 93 deletions
Large diffs are not rendered by default.

Include/dictobject.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ struct _dictobject {
9090

9191
PyAPI_DATA(PyTypeObject) PyDict_Type;
9292

93-
#define PyDict_Check(op) PyObject_TypeCheck(op, &PyDict_Type)
93+
#define PyDict_Check(op) \
94+
PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_DICT_SUBCLASS)
9495
#define PyDict_CheckExact(op) ((op)->ob_type == &PyDict_Type)
9596

9697
PyAPI_FUNC(PyObject *) PyDict_New(void);

Include/listobject.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ typedef struct {
4040

4141
PyAPI_DATA(PyTypeObject) PyList_Type;
4242

43-
#define PyList_Check(op) PyObject_TypeCheck(op, &PyList_Type)
43+
#define PyList_Check(op) \
44+
PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_LIST_SUBCLASS)
4445
#define PyList_CheckExact(op) ((op)->ob_type == &PyList_Type)
4546

4647
PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size);

Include/longobject.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ typedef struct _longobject PyLongObject; /* Revealed in longintrepr.h */
1111

1212
PyAPI_DATA(PyTypeObject) PyLong_Type;
1313

14-
#define PyLong_Check(op) PyObject_TypeCheck(op, &PyLong_Type)
14+
#define PyLong_Check(op) \
15+
PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_LONG_SUBCLASS)
1516
#define PyLong_CheckExact(op) ((op)->ob_type == &PyLong_Type)
1617

1718
PyAPI_FUNC(PyObject *) PyLong_FromLong(long);

Include/object.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */
357357
PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */
358358
PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */
359359

360-
#define PyType_Check(op) PyObject_TypeCheck(op, &PyType_Type)
360+
#define PyType_Check(op) \
361+
PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_TYPE_SUBCLASS)
361362
#define PyType_CheckExact(op) ((op)->ob_type == &PyType_Type)
362363

363364
PyAPI_FUNC(int) PyType_Ready(PyTypeObject *);
@@ -469,11 +470,23 @@ given type object has a specified feature.
469470
#define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION 0
470471
#endif
471472

473+
/* These flags are used to determine if a type is a subclass. */
474+
#define Py_TPFLAGS_INT_SUBCLASS (1L<<23)
475+
#define Py_TPFLAGS_LONG_SUBCLASS (1L<<24)
476+
#define Py_TPFLAGS_LIST_SUBCLASS (1L<<25)
477+
#define Py_TPFLAGS_TUPLE_SUBCLASS (1L<<26)
478+
#define Py_TPFLAGS_STRING_SUBCLASS (1L<<27)
479+
#define Py_TPFLAGS_UNICODE_SUBCLASS (1L<<28)
480+
#define Py_TPFLAGS_DICT_SUBCLASS (1L<<29)
481+
#define Py_TPFLAGS_BASE_EXC_SUBCLASS (1L<<30)
482+
#define Py_TPFLAGS_TYPE_SUBCLASS (1L<<31)
483+
472484
#define Py_TPFLAGS_DEFAULT ( \
473485
Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
474486
0)
475487

476488
#define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0)
489+
#define PyType_FastSubclass(t,f) PyType_HasFeature(t,f)
477490

478491

479492
/*

Include/pyerrors.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,12 @@ PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**);
9494

9595
/* */
9696

97-
#define PyExceptionClass_Check(x) \
98-
(PyType_Check((x)) && PyType_IsSubtype( \
99-
(PyTypeObject*)(x), (PyTypeObject*)PyExc_BaseException))
97+
#define PyExceptionClass_Check(x) \
98+
(PyType_Check((x)) && \
99+
PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS))
100100

101-
102-
#define PyExceptionInstance_Check(x) \
103-
(PyType_IsSubtype((x)->ob_type, (PyTypeObject*)PyExc_BaseException))
101+
#define PyExceptionInstance_Check(x) \
102+
PyType_FastSubclass((x)->ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS)
104103

105104
#define PyExceptionClass_Name(x) \
106105
((char *)(((PyTypeObject*)(x))->tp_name))

Include/stringobject.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ typedef struct {
5555
PyAPI_DATA(PyTypeObject) PyBaseString_Type;
5656
PyAPI_DATA(PyTypeObject) PyString_Type;
5757

58-
#define PyString_Check(op) PyObject_TypeCheck(op, &PyString_Type)
58+
#define PyString_Check(op) \
59+
PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_STRING_SUBCLASS)
5960
#define PyString_CheckExact(op) ((op)->ob_type == &PyString_Type)
6061

6162
PyAPI_FUNC(PyObject *) PyString_FromStringAndSize(const char *, Py_ssize_t);

Include/tupleobject.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ typedef struct {
3333

3434
PyAPI_DATA(PyTypeObject) PyTuple_Type;
3535

36-
#define PyTuple_Check(op) PyObject_TypeCheck(op, &PyTuple_Type)
36+
#define PyTuple_Check(op) \
37+
PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_TUPLE_SUBCLASS)
3738
#define PyTuple_CheckExact(op) ((op)->ob_type == &PyTuple_Type)
3839

3940
PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size);

Include/unicodeobject.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ typedef struct {
392392

393393
PyAPI_DATA(PyTypeObject) PyUnicode_Type;
394394

395-
#define PyUnicode_Check(op) PyObject_TypeCheck(op, &PyUnicode_Type)
395+
#define PyUnicode_Check(op) \
396+
PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_UNICODE_SUBCLASS)
396397
#define PyUnicode_CheckExact(op) ((op)->ob_type == &PyUnicode_Type)
397398

398399
/* Fast access macros */

Objects/dictobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2027,7 +2027,7 @@ PyTypeObject PyDict_Type = {
20272027
0, /* tp_setattro */
20282028
0, /* tp_as_buffer */
20292029
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
2030-
Py_TPFLAGS_BASETYPE, /* tp_flags */
2030+
Py_TPFLAGS_BASETYPE | Py_TPFLAGS_DICT_SUBCLASS, /* tp_flags */
20312031
dictionary_doc, /* tp_doc */
20322032
dict_traverse, /* tp_traverse */
20332033
dict_tp_clear, /* tp_clear */

0 commit comments

Comments
 (0)