summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows/qwindowskeymapper.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2012-10-10 18:27:04 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-16 17:31:31 +0200
commitcd168110e0b9fbcba3f453de14131eb17c82109f (patch)
treeba89398d790c19574ca49e571b8c6640dad14872 /src/plugins/platforms/windows/qwindowskeymapper.h
parentcab891dc502f86cfc670d9facb2f9fa6708e9dd3 (diff)
QWindowsKeyMapper: use a more efficient data structure for 'keyLayout'
Instead of allocating small chunks (40 bytes) on the heap, use a contiguous array to hold them. This always occupies 10240 bytes of memory instead of 1024 (32 bits) or 2048 (64 bits) for the pointer array (plus heap memory which depends on the number of items allocated), but is more cache-friendly and uses less memory when the array isn't sparse. To emulate the nullptr, a new bool has been added (doesn't change sizeof(KeyboardLayoutItem)). Also replace a few more magic numbers by symbolic constants. Change-Id: I7160f600faddd63deea265c89dc6fd857c7b557f Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
Diffstat (limited to 'src/plugins/platforms/windows/qwindowskeymapper.h')
-rw-r--r--src/plugins/platforms/windows/qwindowskeymapper.h23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/plugins/platforms/windows/qwindowskeymapper.h b/src/plugins/platforms/windows/qwindowskeymapper.h
index 7b3f18a42d..6de255facf 100644
--- a/src/plugins/platforms/windows/qwindowskeymapper.h
+++ b/src/plugins/platforms/windows/qwindowskeymapper.h
@@ -51,7 +51,25 @@ QT_BEGIN_NAMESPACE
class QKeyEvent;
class QWindow;
-struct KeyboardLayoutItem;
+/*
+ \internal
+ A Windows KeyboardLayoutItem has 8 possible states:
+ 1. Unmodified
+ 2. Shift
+ 3. Control
+ 4. Control + Shift
+ 5. Alt
+ 6. Alt + Shift
+ 7. Alt + Control
+ 8. Alt + Control + Shift
+*/
+struct KeyboardLayoutItem {
+ uint dirty : 1;
+ uint exists : 1; // whether this item has been initialized (by updatePossibleKeyCodes)
+ quint8 deadkeys;
+ static const size_t NumQtKeys = 9;
+ quint32 qtKey[NumQtKeys]; // Can by any Qt::Key_<foo>, or unicode character
+};
class QWindowsKeyMapper
{
@@ -87,8 +105,9 @@ private:
bool isADeadKey(unsigned int vk_key, unsigned int modifiers);
void deleteLayouts();
- KeyboardLayoutItem *keyLayout[256];
QWindow *m_keyGrabber;
+ static const size_t NumKeyboardLayoutItems = 256;
+ KeyboardLayoutItem keyLayout[NumKeyboardLayoutItems];
};
enum WindowsNativeModifiers {