This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Speed up EnumKey call
Type: Stage:
Components: Windows Versions: Python 2.4
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: alanmcintyre, garth42, georg.brandl, loewis, mmangino, theller
Priority: high Keywords: patch

Created on 2004-06-22 15:22 by garth42, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
_winreg_enumkey_speedup.patch garth42, 2004-06-22 15:22 Patch to spped up _winreg.EnumKey
winreg-enumkey.diff georg.brandl, 2005-07-02 11:08 revised patch
Messages (9)
msg46206 - (view) Author: Garth Bushell (garth42) Date: 2004-06-22 15:22
This patch removes the RegQueryInfoKey call and
replaces it with a call to EnumKeyEx. This greatly
speeds up this call. 

The script below times 

python 2.3              5531 89.7130000591
python 2.4 +patch   5531 0.0469999313354

start = time.time()
i = 0
  while 1:
    _winreg.EnumKey(_winreg.HKEY_CLASSES_ROOT, i)
    i += 1
except WindowsError:
print i, time.time() - start
msg46207 - (view) Author: Mike Mangino (mmangino) Date: 2004-07-14 14:12
Logged In: YES 

This looks good to me, but I think the buffer size is off by
one. I read the SDK to say tha they key can be 255
characters. That means you need to allocate 256 characters
to allow for the null terminator. Could you create a test
case for a max length registry key?
msg46208 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2004-07-14 15:54
Logged In: YES 

I'm curious: Why did you replace RegEnumKey with
RegEnumKeyEx? Are there any advantages of the latter?
msg46209 - (view) Author: Garth Bushell (garth42) Date: 2004-07-14 16:12
Logged In: YES 


Yes you're correct it should be 256 in both cases. Doh! I'll
attach a new patch in a while. but It's easy to mmodify the
patch and up the linit to 256


The advantage of the latter is it returns the Length of the
string returned so we can pass it straight back to the
string creation funtion in python without a strlen.

also the SDK says this....

Note  This function is provided only for compatibility with
16-bit versions of Windows. Applications should use the
RegEnumKeyEx function.

msg46210 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2004-07-26 12:31
Logged In: YES 

Also, please follow the Python style guide for C code, PEP
7. In particular:
- use tabs for indentation, with a tab being worth 8 spaces
- omit spaces after opening and before closing parens
- put the opening brace of a code block on the same line as
the keyword
msg46211 - (view) Author: Alan McIntyre (alanmcintyre) * (Python committer) Date: 2005-02-27 16:59
Logged In: YES 

I think it's a good idea to get 16-bit Windows functions out
of Python per Microsoft's recommendation, especially when
doing so can also help performance.  

It looks like this patch still needs some cleanup and a test
or two.  If nobody else wants to do it I can probably finish
it up.
msg46212 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2005-03-03 08:08
Logged In: YES 

garth42, can you please indicate whether you are willing to
work on the patch, and if so in what time frame?
msg46213 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-07-02 11:08
Logged In: YES 

Attached a revised patch following coding style and adding
additional error handling.

msg46214 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-02-18 23:37
Logged In: YES 

Cleaned up and committed in rev. 42475.
Date User Action Args
2022-04-11 14:56:04adminsetgithub: 40433
2004-06-22 15:22:11garth42create