summaryrefslogtreecommitdiffstats
path: root/PC/_winreg.c
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-02-18 23:35:11 (GMT)
committerGeorg Brandl <georg@python.org>2006-02-18 23:35:11 (GMT)
commit9a928e787cd645b59c094a3696f6680f1615aec9 (patch)
tree686dc861935701391408770e3c6733436d337938 /PC/_winreg.c
parent093ab1aa03f9b049496c3fd8d3006b053aa4f9a4 (diff)
downloadcpython-9a928e787cd645b59c094a3696f6680f1615aec9.zip
cpython-9a928e787cd645b59c094a3696f6680f1615aec9.tar.gz
cpython-9a928e787cd645b59c094a3696f6680f1615aec9.tar.bz2
Patch #977553: speed up RegEnumKey call
Diffstat (limited to 'PC/_winreg.c')
-rw-r--r--PC/_winreg.c31
1 files changed, 12 insertions, 19 deletions
diff --git a/PC/_winreg.c b/PC/_winreg.c
index 965acf1..c97bbc6 100644
--- a/PC/_winreg.c
+++ b/PC/_winreg.c
@@ -1033,30 +1033,23 @@ PyEnumKey(PyObject *self, PyObject *args)
long rc;
PyObject *retStr;
char *retBuf;
- DWORD len;
+ DWORD len = 256; /* includes NULL terminator */
+ char tmpbuf[256]; /* max key name length is 255 */
if (!PyArg_ParseTuple(args, "Oi:EnumKey", &obKey, &index))
return NULL;
if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
return NULL;
-
- if ((rc = RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, &len,
- NULL, NULL, NULL, NULL, NULL, NULL))
- != ERROR_SUCCESS)
- return PyErr_SetFromWindowsErrWithFunction(rc,
- "RegQueryInfoKey");
- ++len; /* include null terminator */
- retStr = PyString_FromStringAndSize(NULL, len);
- if (retStr == NULL)
- return NULL;
- retBuf = PyString_AS_STRING(retStr);
-
- if ((rc = RegEnumKey(hKey, index, retBuf, len)) != ERROR_SUCCESS) {
- Py_DECREF(retStr);
- return PyErr_SetFromWindowsErrWithFunction(rc, "RegEnumKey");
- }
- _PyString_Resize(&retStr, strlen(retBuf));
- return retStr;
+
+ Py_BEGIN_ALLOW_THREADS
+ rc = RegEnumKeyEx(hKey, index, tmpbuf, &len, NULL, NULL, NULL, NULL);
+ Py_END_ALLOW_THREADS
+ if (rc != ERROR_SUCCESS)
+ return PyErr_SetFromWindowsErrWithFunction(rc, "RegEnumKeyEx");
+
+ ++len; /* include null terminator */
+ retStr = PyString_FromStringAndSize(tmpbuf, len);
+ return retStr; /* can be NULL */
}
static PyObject *