diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-04-30 00:33:06 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-04-30 13:05:52 -0400 |
commit | 99c3928cecb0bf4dd7c33c1f7fd078b256aa8a78 (patch) | |
tree | 23c25d6f74a4352ccbd3bf6c37d2092a3ad25495 /gdk/gdkevents.c | |
parent | e5c430266e71289765de6d8bfc40166bcbeff4e7 (diff) | |
download | gtk+-99c3928cecb0bf4dd7c33c1f7fd078b256aa8a78.tar.gz |
keymap: Cache key info
We currently calling gdk_display_map_keyval up to
once per key event per shortcut trigger, and that function
does an expensive loop over the entire keymap and
allocates an array. Avoid this by caching the entries
in a single array, and have a lookup table for finding
the entries for a keyval.
To do this, change the GdkKeymap.get_entries_for_keyval
signature, and change the ::keys-changed signal to be
RUN_FIRST, since we want to clear the cache in the class
handler before running signal handlers. These changes are
possible now, since keymaps are no longer public API.
Diffstat (limited to 'gdk/gdkevents.c')
-rw-r--r-- | gdk/gdkevents.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c index 41706885af..9d2a689381 100644 --- a/gdk/gdkevents.c +++ b/gdk/gdkevents.c @@ -1604,6 +1604,7 @@ gdk_key_event_matches (GdkEvent *event, GdkModifierType modifiers) { GdkKeyEvent *self = (GdkKeyEvent *) event; + GdkKeymap *keymap; guint keycode; GdkModifierType state; guint ev_keyval; @@ -1644,7 +1645,7 @@ gdk_key_event_matches (GdkEvent *event, { /* modifier match */ GdkKeymapKey *keys; - int n_keys; + guint n_keys; int i; guint key; @@ -1667,7 +1668,8 @@ gdk_key_event_matches (GdkEvent *event, return GDK_KEY_MATCH_EXACT; } - gdk_display_map_keyval (gdk_event_get_display (event), keyval, &keys, &n_keys); + keymap = gdk_display_get_keymap (gdk_event_get_display (event)); + gdk_keymap_get_cached_entries_for_keyval (keymap, keyval, &keys, &n_keys); for (i = 0; i < n_keys; i++) { @@ -1676,14 +1678,9 @@ gdk_key_event_matches (GdkEvent *event, /* Only match for group if it's an accel mod */ (!group_mod_is_accel_mod || keys[i].group == layout)) { - /* partial match */ - g_free (keys); - return GDK_KEY_MATCH_PARTIAL; } } - - g_free (keys); } return GDK_KEY_MATCH_NONE; |