Commit f76859bc87a0d499ec25f04ef95867e97bec74c3

Ran Benita 2012-10-23T09:58:11

keymap: use plain array for keymap->group_names Again it is not resized. Signed-off-by: Ran Benita <ran234@gmail.com>

diff --git a/src/keymap-dump.c b/src/keymap-dump.c
index 4306a7d..5bf0774 100644
--- a/src/keymap-dump.c
+++ b/src/keymap-dump.c
@@ -517,8 +517,7 @@ static bool
 write_symbols(struct xkb_keymap *keymap, struct buf *buf)
 {
     struct xkb_key *key;
-    xkb_layout_index_t group, tmp;
-    xkb_atom_t *group_name;
+    xkb_layout_index_t group;
     bool showActions;
 
     if (keymap->symbols_section_name)
@@ -527,16 +526,12 @@ write_symbols(struct xkb_keymap *keymap, struct buf *buf)
     else
         write_buf(buf, "\txkb_symbols {\n\n");
 
-    tmp = 0;
-    darray_enumerate(group, group_name, keymap->group_names) {
-        if (!*group_name)
-            continue;
-        write_buf(buf,
-                  "\t\tname[group%d]=\"%s\";\n", group + 1,
-                  xkb_atom_text(keymap->ctx, *group_name));
-        tmp++;
-    }
-    if (tmp > 0)
+    for (group = 0; group < keymap->num_group_names; group++)
+        if (keymap->group_names[group])
+            write_buf(buf,
+                      "\t\tname[group%d]=\"%s\";\n", group + 1,
+                      xkb_atom_text(keymap->ctx, keymap->group_names[group]));
+    if (group > 0)
         write_buf(buf, "\n");
 
     xkb_foreach_key(key, keymap) {
diff --git a/src/keymap.c b/src/keymap.c
index 63e9853..6736c2c 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -108,7 +108,7 @@ xkb_keymap_unref(struct xkb_keymap *keymap)
     free(keymap->types);
     darray_free(keymap->sym_interprets);
     darray_free(keymap->key_aliases);
-    darray_free(keymap->group_names);
+    free(keymap->group_names);
     darray_free(keymap->mods);
     darray_free(keymap->indicators);
     free(keymap->keycodes_section_name);
@@ -176,11 +176,10 @@ xkb_keymap_num_layouts(struct xkb_keymap *keymap)
 XKB_EXPORT const char *
 xkb_keymap_layout_get_name(struct xkb_keymap *keymap, xkb_layout_index_t idx)
 {
-    if (idx >= xkb_keymap_num_layouts(keymap) ||
-        idx >= darray_size(keymap->group_names))
+    if (idx >= keymap->num_group_names)
         return NULL;
 
-    return xkb_atom_text(keymap->ctx, darray_item(keymap->group_names, idx));
+    return xkb_atom_text(keymap->ctx, keymap->group_names[idx]);
 }
 
 /**
@@ -190,14 +189,13 @@ XKB_EXPORT xkb_layout_index_t
 xkb_keymap_layout_get_index(struct xkb_keymap *keymap, const char *name)
 {
     xkb_atom_t atom = xkb_atom_lookup(keymap->ctx, name);
-    xkb_atom_t *group_name;
     xkb_layout_index_t i;
 
     if (atom == XKB_ATOM_NONE)
         return XKB_LAYOUT_INVALID;
 
-    darray_enumerate(i, group_name, keymap->group_names)
-        if (*group_name == atom)
+    for (i = 0; i < keymap->num_group_names; i++)
+        if (keymap->group_names[i] == atom)
             return i;
 
     return XKB_LAYOUT_INVALID;
diff --git a/src/keymap.h b/src/keymap.h
index 1684979..483ee90 100644
--- a/src/keymap.h
+++ b/src/keymap.h
@@ -359,8 +359,6 @@ struct xkb_key {
     struct xkb_group *groups;
 };
 
-typedef darray(xkb_atom_t) darray_xkb_atom_t;
-
 struct xkb_mod {
     xkb_atom_t name;
     enum mod_type type;
@@ -393,7 +391,9 @@ struct xkb_keymap {
 
     /* Number of groups in the key with the most groups. */
     xkb_layout_index_t num_groups;
-    darray_xkb_atom_t group_names;
+    /* Not all groups must have names. */
+    xkb_layout_index_t num_group_names;
+    xkb_atom_t *group_names;
 
     darray(struct xkb_indicator_map) indicators;
 
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index a99851b..6f87a7b 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -180,7 +180,7 @@ typedef struct {
     darray(KeyInfo) keys;
     KeyInfo dflt;
     ActionsInfo *actions;
-    darray_xkb_atom_t group_names;
+    darray(xkb_atom_t) group_names;
     darray(ModMapEntry) modMaps;
 
     struct xkb_keymap *keymap;
@@ -1587,7 +1587,8 @@ CopySymbolsToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info)
 
     keymap->symbols_section_name = strdup_safe(info->name);
 
-    keymap->group_names = info->group_names;
+    keymap->num_group_names = darray_size(info->group_names);
+    keymap->group_names = darray_mem(info->group_names, 0);
     darray_init(info->group_names);
 
     darray_foreach(keyi, info->keys)