keymap: don't use darray for sym_interprets We want xkb_keymap to be easy to handle everywhere. Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
diff --git a/src/keymap.c b/src/keymap.c
index 8205bab..4fbf33e 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -106,7 +106,7 @@ xkb_keymap_unref(struct xkb_keymap *keymap)
free(keymap->types[i].level_names);
}
free(keymap->types);
- darray_free(keymap->sym_interprets);
+ free(keymap->sym_interprets);
free(keymap->key_aliases);
free(keymap->group_names);
darray_free(keymap->mods);
diff --git a/src/keymap.h b/src/keymap.h
index 7d51184..8291fa0 100644
--- a/src/keymap.h
+++ b/src/keymap.h
@@ -386,7 +386,8 @@ struct xkb_keymap {
struct xkb_key_type *types;
unsigned int num_types;
- darray(struct xkb_sym_interpret) sym_interprets;
+ unsigned int num_sym_interprets;
+ struct xkb_sym_interpret *sym_interprets;
darray(struct xkb_mod) mods;
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 3a14dc6..550819b 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -958,15 +958,21 @@ HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
}
}
+/* Temporary struct for CopyInterps. */
+struct collect {
+ darray(struct xkb_sym_interpret) sym_interprets;
+};
+
static void
-CopyInterps(CompatInfo *info, bool needSymbol, enum xkb_match_operation pred)
+CopyInterps(CompatInfo *info, bool needSymbol, enum xkb_match_operation pred,
+ struct collect *collect)
{
SymInterpInfo *si;
darray_foreach(si, info->interps)
if (si->interp.match == pred &&
(si->interp.sym != XKB_KEY_NoSymbol) == needSymbol)
- darray_append(info->keymap->sym_interprets, si->interp);
+ darray_append(collect->sym_interprets, si->interp);
}
static void
@@ -1028,17 +1034,23 @@ CopyCompatToKeymap(struct xkb_keymap *keymap, CompatInfo *info)
XkbEscapeMapName(keymap->compat_section_name);
if (!darray_empty(info->interps)) {
+ struct collect collect;
+ darray_init(collect.sym_interprets);
+
/* Most specific to least specific. */
- CopyInterps(info, true, MATCH_EXACTLY);
- CopyInterps(info, true, MATCH_ALL);
- CopyInterps(info, true, MATCH_NONE);
- CopyInterps(info, true, MATCH_ANY);
- CopyInterps(info, true, MATCH_ANY_OR_NONE);
- CopyInterps(info, false, MATCH_EXACTLY);
- CopyInterps(info, false, MATCH_ALL);
- CopyInterps(info, false, MATCH_NONE);
- CopyInterps(info, false, MATCH_ANY);
- CopyInterps(info, false, MATCH_ANY_OR_NONE);
+ CopyInterps(info, true, MATCH_EXACTLY, &collect);
+ CopyInterps(info, true, MATCH_ALL, &collect);
+ CopyInterps(info, true, MATCH_NONE, &collect);
+ CopyInterps(info, true, MATCH_ANY, &collect);
+ CopyInterps(info, true, MATCH_ANY_OR_NONE, &collect);
+ CopyInterps(info, false, MATCH_EXACTLY, &collect);
+ CopyInterps(info, false, MATCH_ALL, &collect);
+ CopyInterps(info, false, MATCH_NONE, &collect);
+ CopyInterps(info, false, MATCH_ANY, &collect);
+ CopyInterps(info, false, MATCH_ANY_OR_NONE, &collect);
+
+ keymap->num_sym_interprets = darray_size(collect.sym_interprets);
+ keymap->sym_interprets = darray_mem(collect.sym_interprets, 0);
}
CopyLedMapDefs(info);
diff --git a/src/xkbcomp/keymap-dump.c b/src/xkbcomp/keymap-dump.c
index 0933873..71b9a8c 100644
--- a/src/xkbcomp/keymap-dump.c
+++ b/src/xkbcomp/keymap-dump.c
@@ -416,7 +416,6 @@ write_action(struct xkb_keymap *keymap, struct buf *buf,
static bool
write_compat(struct xkb_keymap *keymap, struct buf *buf)
{
- const struct xkb_sym_interpret *si;
const struct xkb_led *led;
if (keymap->compat_section_name)
@@ -430,7 +429,9 @@ write_compat(struct xkb_keymap *keymap, struct buf *buf)
write_buf(buf, "\tinterpret.useModMapMods= AnyLevel;\n");
write_buf(buf, "\tinterpret.repeat= False;\n");
- darray_foreach(si, keymap->sym_interprets) {
+ for (int i = 0; i < keymap->num_sym_interprets; i++) {
+ const struct xkb_sym_interpret *si = &keymap->sym_interprets[i];
+
write_buf(buf, "\tinterpret %s+%s(%s) {\n",
si->sym ? KeysymText(keymap->ctx, si->sym) : "Any",
SIMatchText(si->match),
diff --git a/src/xkbcomp/keymap.c b/src/xkbcomp/keymap.c
index bed3930..320216e 100644
--- a/src/xkbcomp/keymap.c
+++ b/src/xkbcomp/keymap.c
@@ -78,7 +78,6 @@ static const struct xkb_sym_interpret *
FindInterpForKey(struct xkb_keymap *keymap, const struct xkb_key *key,
xkb_layout_index_t group, xkb_level_index_t level)
{
- const struct xkb_sym_interpret *interp;
const xkb_keysym_t *syms;
int num_syms;
@@ -93,7 +92,9 @@ FindInterpForKey(struct xkb_keymap *keymap, const struct xkb_key *key,
* sym_interprets array from the most specific to the least specific,
* such that when we find a match we return immediately.
*/
- darray_foreach(interp, keymap->sym_interprets) {
+ for (int i = 0; i < keymap->num_sym_interprets; i++) {
+ const struct xkb_sym_interpret *interp = &keymap->sym_interprets[i];
+
xkb_mod_mask_t mods;
bool found = false;