keymap: use plain array for keymap->group_names Again it is not resized. 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
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)