Anonymous avatar Anonymous committed 1567c01

Speed up PyType_stgdict and PyObject_stgdict.

Comments (0)

Files changed (1)

Modules/_ctypes/stgdict.c

 	type = (PyTypeObject *)obj;
 	if (!PyType_HasFeature(type, Py_TPFLAGS_HAVE_CLASS))
 		return NULL;
-	if (!type->tp_dict || !StgDict_Check(type->tp_dict))
+	if (!type->tp_dict || !StgDict_CheckExact(type->tp_dict))
 		return NULL;
 	return (StgDictObject *)type->tp_dict;
 }
 
 /* May return NULL, but does not set an exception! */
+/*
+  This function should be as fast as possible, so we don't call PyType_stgdict
+  above but inline the code, and avoid the PyType_Check().
+*/
 StgDictObject *
 PyObject_stgdict(PyObject *self)
 {
-	return PyType_stgdict((PyObject *)self->ob_type);
+	PyTypeObject *type = self->ob_type;
+	if (!PyType_HasFeature(type, Py_TPFLAGS_HAVE_CLASS))
+		return NULL;
+	if (!type->tp_dict || !StgDict_CheckExact(type->tp_dict))
+		return NULL;
+	return (StgDictObject *)type->tp_dict;
 }
 
 /* descr is the descriptor for a field marked as anonymous.  Get all the
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.