summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-02-14 22:40:11 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-02-14 22:40:11 (GMT)
commite247f0037f87d9e0a2582d0beb941fba6357454d (patch)
tree83ebf520f9a38bab1aa8d6b7310e4a2694f5e35b /Objects
parente7fb0c51141705abc1444b9d8ae2d8ccd750d1a4 (diff)
downloadcpython-e247f0037f87d9e0a2582d0beb941fba6357454d.zip
cpython-e247f0037f87d9e0a2582d0beb941fba6357454d.tar.gz
cpython-e247f0037f87d9e0a2582d0beb941fba6357454d.tar.bz2
Use a static and interned string for __subclasscheck__ and __instancecheck__ as suggested by Thomas Heller in #2115
Diffstat (limited to 'Objects')
-rw-r--r--Objects/abstract.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 89a78c6..93d73bb 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -2401,10 +2401,17 @@ recursive_isinstance(PyObject *inst, PyObject *cls, int recursion_depth)
int
PyObject_IsInstance(PyObject *inst, PyObject *cls)
{
+ static PyObject *name = NULL;
PyObject *t, *v, *tb;
PyObject *checker;
PyErr_Fetch(&t, &v, &tb);
- checker = PyObject_GetAttrString(cls, "__instancecheck__");
+
+ if (name == NULL) {
+ name = PyString_InternFromString("__instancecheck__");
+ if (name == NULL)
+ return -1;
+ }
+ checker = PyObject_GetAttr(cls, name);
PyErr_Restore(t, v, tb);
if (checker != NULL) {
PyObject *res;
@@ -2477,10 +2484,17 @@ recursive_issubclass(PyObject *derived, PyObject *cls, int recursion_depth)
int
PyObject_IsSubclass(PyObject *derived, PyObject *cls)
{
+ static PyObject *name = NULL;
PyObject *t, *v, *tb;
PyObject *checker;
PyErr_Fetch(&t, &v, &tb);
- checker = PyObject_GetAttrString(cls, "__subclasscheck__");
+
+ if (name == NULL) {
+ name = PyString_InternFromString("__subclasscheck__");
+ if (name == NULL)
+ return -1;
+ }
+ checker = PyObject_GetAttr(cls, name);
PyErr_Restore(t, v, tb);
if (checker != NULL) {
PyObject *res;