Francois Gouget : kernel32: Simplify and optimize create_(system, env) _registry_keys().

Alexandre Julliard julliard at winehq.org
Wed Nov 19 08:34:47 CST 2008


Module: wine
Branch: master
Commit: 0a66633ce310eee7556cb3bba9d525faa1ae6115
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=0a66633ce310eee7556cb3bba9d525faa1ae6115

Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Tue Nov 18 21:58:38 2008 +0100

kernel32: Simplify and optimize create_(system,env)_registry_keys().

---

 dlls/kernel32/cpu.c |   28 +++++++++++++++-------------
 1 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/dlls/kernel32/cpu.c b/dlls/kernel32/cpu.c
index 6f50009..63ca277 100644
--- a/dlls/kernel32/cpu.c
+++ b/dlls/kernel32/cpu.c
@@ -132,7 +132,7 @@ static void create_system_registry_keys( const SYSTEM_INFO *info )
     if (NtCreateKey( &system_key, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL )) return;
 
     RtlInitUnicodeString( &valueW, IdentifierW );
-    NtSetValueKey( system_key, &valueW, 0, REG_SZ, SysidW, (strlenW(SysidW)+1) * sizeof(WCHAR) );
+    NtSetValueKey( system_key, &valueW, 0, REG_SZ, SysidW, sizeof(SysidW) );
 
     attr.RootDirectory = system_key;
     RtlInitUnicodeString( &nameW, fpuW );
@@ -151,6 +151,7 @@ static void create_system_registry_keys( const SYSTEM_INFO *info )
             if (!NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ))
             {
                 WCHAR idW[60];
+                DWORD sizeW;
                 DWORD cpuMHz = cpuHz / 1000000;
 
                 /*TODO: report 64bit processors properly*/
@@ -158,12 +159,12 @@ static void create_system_registry_keys( const SYSTEM_INFO *info )
                 sprintf( id, "x86 Family %d Model %d Stepping %d",
                          info->wProcessorLevel, HIBYTE(info->wProcessorRevision), LOBYTE(info->wProcessorRevision) );
 
-                RtlMultiByteToUnicodeN( idW, sizeof(idW), NULL, id, strlen(id)+1 );
-                NtSetValueKey( hkey, &valueW, 0, REG_SZ, idW, (strlenW(idW)+1)*sizeof(WCHAR) );
+                RtlMultiByteToUnicodeN( idW, sizeof(idW), &sizeW, id, strlen(id)+1 );
+                NtSetValueKey( hkey, &valueW, 0, REG_SZ, idW, sizeW );
 
                 /*TODO; report amd's properly*/
                 RtlInitUnicodeString( &valueW, VendorIdentifierW );
-                NtSetValueKey( hkey, &valueW, 0, REG_SZ, VenidIntelW, (strlenW(VenidIntelW)+1) * sizeof(WCHAR) );
+                NtSetValueKey( hkey, &valueW, 0, REG_SZ, VenidIntelW, sizeof(VenidIntelW) );
 
                 RtlInitUnicodeString( &valueW, mhzKeyW );
                 NtSetValueKey( hkey, &valueW, 0, REG_DWORD, &cpuMHz, sizeof(DWORD) );
@@ -194,6 +195,7 @@ static void create_env_registry_keys( const SYSTEM_INFO *info )
     HANDLE env_key;
     OBJECT_ATTRIBUTES attr;
     UNICODE_STRING nameW, valueW;
+    DWORD sizeW;
 
     char nProc[10],id[60],procLevel[10],rev[10];
     WCHAR nProcW[10],idW[60],procLevelW[10],revW[10];
@@ -214,31 +216,31 @@ static void create_env_registry_keys( const SYSTEM_INFO *info )
     if (NtCreateKey( &env_key, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL )) return;
 
     sprintf( nProc, "%d", info->dwNumberOfProcessors );
-    RtlMultiByteToUnicodeN( nProcW, sizeof(nProcW), NULL, nProc, strlen(nProc)+1 );
+    RtlMultiByteToUnicodeN( nProcW, sizeof(nProcW), &sizeW, nProc, strlen(nProc)+1 );
     RtlInitUnicodeString( &valueW, NumProcW );
-    NtSetValueKey( env_key, &valueW, 0, REG_SZ, nProcW, (strlenW(nProcW)+1)*sizeof(WCHAR) );
+    NtSetValueKey( env_key, &valueW, 0, REG_SZ, nProcW, sizeW );
 
     /* TODO: currently hardcoded x86, add different processors */
     RtlInitUnicodeString( &valueW, ProcArchW );
-    NtSetValueKey( env_key, &valueW, 0, REG_SZ, x86W, (strlenW(x86W)+1) * sizeof(WCHAR) );
+    NtSetValueKey( env_key, &valueW, 0, REG_SZ, x86W, sizeof(x86W) );
 
     /* TODO: currently hardcoded Intel, add different processors */
     sprintf( id, "x86 Family %d Model %d Stepping %d, GenuineIntel",
         info->wProcessorLevel, HIBYTE(info->wProcessorRevision), LOBYTE(info->wProcessorRevision) );
-    RtlMultiByteToUnicodeN( idW, sizeof(idW), NULL, id, strlen(id)+1 );
+    RtlMultiByteToUnicodeN( idW, sizeof(idW), &sizeW, id, strlen(id)+1 );
     RtlInitUnicodeString( &valueW, ProcIdW );
-    NtSetValueKey( env_key, &valueW, 0, REG_SZ, idW, (strlenW(idW)+1)*sizeof(WCHAR) );
+    NtSetValueKey( env_key, &valueW, 0, REG_SZ, idW, sizeW );
 
     sprintf( procLevel, "%d", info->wProcessorLevel );
-    RtlMultiByteToUnicodeN( procLevelW, sizeof(procLevelW), NULL, procLevel, strlen(procLevel)+1 );
+    RtlMultiByteToUnicodeN( procLevelW, sizeof(procLevelW), &sizeW, procLevel, strlen(procLevel)+1 );
     RtlInitUnicodeString( &valueW, ProcLvlW );
-    NtSetValueKey( env_key, &valueW, 0, REG_SZ, procLevelW, (strlenW(procLevelW)+1)*sizeof(WCHAR) );
+    NtSetValueKey( env_key, &valueW, 0, REG_SZ, procLevelW, sizeW );
 
     /* Properly report model/stepping */
     sprintf( rev, "%04x", info->wProcessorRevision);
-    RtlMultiByteToUnicodeN( revW, sizeof(revW), NULL, rev, strlen(rev)+1 );
+    RtlMultiByteToUnicodeN( revW, sizeof(revW), &sizeW, rev, strlen(rev)+1 );
     RtlInitUnicodeString( &valueW, ProcRevW );
-    NtSetValueKey( env_key, &valueW, 0, REG_SZ, revW, (strlenW(revW)+1)*sizeof(WCHAR) );
+    NtSetValueKey( env_key, &valueW, 0, REG_SZ, revW, sizeW );
 
     NtClose( env_key );
 }




More information about the wine-cvs mailing list