From: Thomas Heller Date: Fri, 6 Jun 2008 18:37:55 +0000 (+0000) Subject: Performance improvement: Use PyDict_Get/SetItem instead of X-Git-Tag: v2.6b1~144 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f89b04c164e58f60295b678d845a777fc59f8c8a;p=python Performance improvement: Use PyDict_Get/SetItem instead of PyDict_Get/SetItemString. --- diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index 89a4d68250..12b0d7a410 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -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; }