Performance improvement: Use PyDict_Get/SetItem instead of

PyDict_Get/SetItemString.
This commit is contained in:
Thomas Heller 2008-06-06 18:37:55 +00:00
parent d82a9c1618
commit f89b04c164
1 changed files with 9 additions and 3 deletions

View File

@ -122,12 +122,18 @@ get_error_object(int **pspace)
{
PyObject *dict = PyThreadState_GetDict();
PyObject *errobj;
static PyObject *error_object_name;
if (dict == 0) {
PyErr_SetString(PyExc_RuntimeError,
"cannot get thread state");
return NULL;
}
errobj = PyDict_GetItemString(dict, "ctypes.error_object");
if (error_object_name == NULL) {
error_object_name = PyString_InternFromString("ctypes.error_object");
if (error_object_name == NULL)
return NULL;
}
errobj = PyDict_GetItem(dict, error_object_name);
if (errobj)
Py_INCREF(errobj);
else {
@ -138,8 +144,8 @@ get_error_object(int **pspace)
errobj = PyCObject_FromVoidPtr(space, PyMem_Free);
if (errobj == NULL)
return NULL;
if (-1 == PyDict_SetItemString(dict, "ctypes.error_object",
errobj)) {
if (-1 == PyDict_SetItem(dict, error_object_name,
errobj)) {
Py_DECREF(errobj);
return NULL;
}