To avoid iterating the registry every time GetKeyboardLayoutNameW is called.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com ---
This is causing some slow down in "Monster Boy and the cursed Kingdom" for instance, which is calling GetKeyboardLayoutNameW frequently. This is also more likely to be slow with Wine Staging, which adds registry keys for a lot of different layouts.
dlls/user32/input.c | 10 ++++++++++ dlls/user32/user_private.h | 1 + 2 files changed, 11 insertions(+)
diff --git a/dlls/user32/input.c b/dlls/user32/input.c index adeb4f66804..1b2360ea083 100644 --- a/dlls/user32/input.c +++ b/dlls/user32/input.c @@ -1129,6 +1129,7 @@ BOOL WINAPI GetKeyboardLayoutNameA(LPSTR pszKLID) */ BOOL WINAPI GetKeyboardLayoutNameW( WCHAR *name ) { + struct user_thread_info *info = get_user_thread_info(); WCHAR klid[KL_NAMELENGTH], value[5]; DWORD value_size, tmp, i = 0; HKEY hkey; @@ -1142,6 +1143,12 @@ BOOL WINAPI GetKeyboardLayoutNameW( WCHAR *name ) return FALSE; }
+ if (info->kbd_layout_id) + { + swprintf( name, KL_NAMELENGTH, L"%08X", info->kbd_layout_id ); + return TRUE; + } + layout = GetKeyboardLayout( 0 ); tmp = HandleToUlong( layout ); if (HIWORD( tmp ) == LOWORD( tmp )) tmp = LOWORD( tmp ); @@ -1166,6 +1173,8 @@ BOOL WINAPI GetKeyboardLayoutNameW( WCHAR *name ) RegCloseKey( hkey ); }
+ info->kbd_layout_id = wcstoul( name, NULL, 16 ); + TRACE_(keyboard)( "ret %s\n", debugstr_w( name ) ); return TRUE; } @@ -1394,6 +1403,7 @@ HKL WINAPI ActivateKeyboardLayout( HKL layout, UINT flags )
old_layout = info->kbd_layout; info->kbd_layout = layout; + if (old_layout != layout) info->kbd_layout_id = 0;
if (!old_layout) return get_locale_kbd_layout(); return old_layout; diff --git a/dlls/user32/user_private.h b/dlls/user32/user_private.h index 1c7ac3355bc..1bc41888891 100644 --- a/dlls/user32/user_private.h +++ b/dlls/user32/user_private.h @@ -198,6 +198,7 @@ struct user_thread_info ULONG_PTR GetMessageExtraInfoVal; /* Value for GetMessageExtraInfo */ struct user_key_state_info *key_state; /* Cache of global key state */ HKL kbd_layout; /* Current keyboard layout */ + DWORD kbd_layout_id; /* Current keyboard layout ID */ HWND top_window; /* Desktop window */ HWND msg_window; /* HWND_MESSAGE parent window */ struct rawinput_thread_data *rawinput; /* RawInput thread local data / buffer */