From c6832927fb8467aba52eeee20ae3b706b1abf633 Mon Sep 17 00:00:00 2001 From: Eldar Abusalimov Date: Sat, 25 Oct 2014 15:54:36 +0400 Subject: [PATCH 09/15] (minor) PyType_IsSubtype: extract a check using tp_base Extract a subtype check through a type->tp_base chain into a separate type_is_subtype_base_chain function --- Objects/typeobject.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 491bcdd..5e8a9c0 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -1297,6 +1297,18 @@ static PyTypeObject *solid_base(PyTypeObject *type); /* type test with subclassing support */ +Py_LOCAL_INLINE(int) +type_is_subtype_base_chain(PyTypeObject *a, PyTypeObject *b) +{ + do { + if (a == b) + return 1; + a = a->tp_base; + } while (a != NULL); + + return (b == &PyBaseObject_Type); +} + int PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b) { @@ -1315,15 +1327,9 @@ PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b) } return 0; } - else { + else /* a is not completely initilized yet; follow tp_base */ - do { - if (a == b) - return 1; - a = a->tp_base; - } while (a != NULL); - return b == &PyBaseObject_Type; - } + return type_is_subtype_base_chain(a, b); } /* Internal routines to do a method lookup in the type -- 2.1.1