From db639be6dfa9fecfbb867b878a13ae6af149b549 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 3 Sep 2012 10:23:44 +0300 Subject: [PATCH] keymap: optimize FindInterpsForKey a bit Signed-off-by: Ran Benita --- src/xkbcomp/compat.c | 1 + src/xkbcomp/keymap.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c index c387310..b6d15d7 100644 --- a/src/xkbcomp/compat.c +++ b/src/xkbcomp/compat.c @@ -1074,6 +1074,7 @@ CopyCompatToKeymap(struct xkb_keymap *keymap, CompatInfo *info) keymap->compat_section_name = strdup_safe(info->name); if (!darray_empty(info->interps)) { + /* Most specific to least specific. */ CopyInterps(info, true, XkbSI_Exactly); CopyInterps(info, true, XkbSI_AllOf | XkbSI_NoneOf); CopyInterps(info, true, XkbSI_AnyOf); diff --git a/src/xkbcomp/keymap.c b/src/xkbcomp/keymap.c index ca281f7..3fc8915 100644 --- a/src/xkbcomp/keymap.c +++ b/src/xkbcomp/keymap.c @@ -83,7 +83,6 @@ static struct xkb_sym_interpret * FindInterpForKey(struct xkb_keymap *keymap, struct xkb_key *key, xkb_group_index_t group, xkb_level_index_t level) { - struct xkb_sym_interpret *ret = NULL; struct xkb_sym_interpret *interp; const xkb_keysym_t *syms; int num_syms; @@ -92,6 +91,12 @@ FindInterpForKey(struct xkb_keymap *keymap, struct xkb_key *key, if (num_syms == 0) return NULL; + /* + * There may be multiple matchings interprets; we should always return + * the most specific. Here we rely on compat.c to set up the + * sym_interpret array from the most specific to the least specific, + * such that when we find a match we return immediately. + */ darray_foreach(interp, keymap->sym_interpret) { uint32_t mods; bool found; @@ -126,13 +131,11 @@ FindInterpForKey(struct xkb_keymap *keymap, struct xkb_key *key, break; } - if (found && interp->sym != XKB_KEY_NoSymbol) + if (found) return interp; - else if (found && !ret) - ret = interp; } - return ret; + return NULL; } static bool -- 2.7.4