Commit 9ffe9dae1dbb09b98b0bf0e9c6bfee1b79abeafe

Ran Benita 2013-07-21T09:48:12

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>

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;