diff options
author | Thomas Heller <theller@ctypes.org> | 2008-06-06 18:37:55 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2008-06-06 18:37:55 (GMT) |
commit | f89b04c164e58f60295b678d845a777fc59f8c8a (patch) | |
tree | d12e994080226ba5cc0e2eea7adbbf5a5dd201f4 /Modules | |
parent | d82a9c1618be09690ddab73aa3b1f1f994b7c402 (diff) | |
download | cpython-f89b04c164e58f60295b678d845a777fc59f8c8a.zip cpython-f89b04c164e58f60295b678d845a777fc59f8c8a.tar.gz cpython-f89b04c164e58f60295b678d845a777fc59f8c8a.tar.bz2 |
Performance improvement: Use PyDict_Get/SetItem instead of
PyDict_Get/SetItemString.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_ctypes/callproc.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index 89a4d68..12b0d7a 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; } |