]> granicus.if.org Git - python/commitdiff
Use a static and interned string for __subclasscheck__ and __instancecheck__ as sugge...
authorChristian Heimes <christian@cheimes.de>
Thu, 14 Feb 2008 22:40:11 +0000 (22:40 +0000)
committerChristian Heimes <christian@cheimes.de>
Thu, 14 Feb 2008 22:40:11 +0000 (22:40 +0000)
Objects/abstract.c

index 89a78c6da6af0260a2104008bbacee58480fa43d..93d73bb148990cba97cf4242715ed332d7d78b97 100644 (file)
@@ -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;